LWDB
Time limit9sMemory limit1024 MB
Paint every tree vertex within weighted distance d of a given vertex with a color, and report a vertex's current color, with later paints overriding earlier ones.
- Level
Medium7 of 10
- Topics
- Tree, Divide and conquer
- Solved
- No attempts yet
Problem
The Large Wood Database (LWDB) stores any existing tree and paints it securely. The update adds new functionality, so the graph theory behind it needs another look. A weighted tree is stored in LWDB. The LWDB Management System (LWDB MS) accepts two query types:
1 v d c: paint every tree vertex whose distance from vertex is at most with color . Every vertex starts with color .2 v: return the color of vertex .
You need to prototype LWDB MS and answer all user queries.
Input
The first line contains (), the number of tree vertices. Each of the next lines contains three integers , , (, , ), meaning branch connects vertices and with weight . The next line contains (), the number of queries. Each of the next lines is one of the following:
1 v d c(, , )2 v()
Output
For each query of type 2, print the color of the requested vertex on its own line.