Ald
Time limit4sMemory limit2048 MB
Given a tree, maintain a multiset of paths under insertions and deletions and answer how many vertices lie within distance d of every path.
- Level
Hard9 of 10
- Topics
- Tree, Divide and conquer, Segment tree
- Solved
- No attempts yet
Problem
A tree is given. It has vertices, labeled from to .
Denote the path between vertices and as . The -set of a path is the set of all vertices of the tree whose distance from at least one vertex on the path is at most . For example, the -set of a path is the set of its own vertices. The distance between two vertices is the number of edges on the path connecting them.
Let be a multiset of tree paths. Initially, is empty. Process the following queries.
- 1 : add the path to ().
- 2 : delete one copy of the path from (). and denote the same path. For example, if , then the query 2 3 2 leaves . Before this query, it is guaranteed that contains or .
- 3 : print the size of the intersection of the -sets of all paths in (). If is empty, print .
Input
The first line contains the number of test cases (). Each test case starts with a line containing the number of vertices and the number of queries (). The next lines each contain the endpoints and of the -th edge. The last lines contain queries in the format described above. The sum of over all test cases does not exceed , and the sum of over all test cases does not exceed .
Output
For each query of type 3, print the answer on its own line.