Tree and Queries 14
Time limit5sMemory limit1024 MB
Given a tree with unit-weight edges, each query asks how many vertices lie within distance r_i of at least k-1 of the k given centers v_i.
- Level
Hard8 of 10
- Topics
- Tree, Divide and conquer
- Solved
- No attempts yet
Problem
The tree has vertices numbered from 1 to . Every edge has weight 1.
Write a program that processes the following query.
k v1 r1 v2 r2 ... vk rk: A vertex satisfies condition if its distance from is at most . Among all vertices in the tree, count the vertices that satisfy at least of the conditions in the query.
Input
The first line contains ().
Each of the next lines contains two vertex numbers and connected by an edge ().
The next line contains (), the number of queries.
Each query spans lines, not one line. The queries follow in this format. (, , )
The sum of over all queries does not exceed .
Output
Print the answer to each query on its own line.