Ald
시간 제한4초메모리 제한2048 MB
트리 위 경로들의 중복 집합을 삽입과 삭제로 관리하면서, 각 질의 d마다 저장된 모든 경로에서 거리 d 이내에 있는 정점의 개수를 구한다.
문제
You are given a tree. The tree has vertices, labeled from to .
Let us denote the path between vertices and as . Let the -set of a path be the set of vertices on the tree located within a distance from at least one vertex of the path. For example, the -set of a path is the set of its vertices. The distance between vertices is the number of edges on the path between these vertices.
Let be a multiset of tree paths. Initially, is empty. Your task is to process the following queries:
- "
1": add path into (). - "
2": delete a single path from (). Note that and denote the same path. For example, if , then after a query "2 3 2", we will have . Before this query, it is guaranteed that at least one path or is present in . - "
3": print the size of intersection of -sets of all paths from (). If is empty, print .
입력
The first line contains an integer , the number of test cases (). The test cases follow.
The first line of each test case contains two integers and (), the number of vertices in the tree and the number of queries.
Each of the following lines contains two integers and : indices of vertices connected by the -th edge of the tree ().
The following lines contain queries in the format described in the statement.
The sum of over all test cases does not exceed . The sum of over all test cases does not exceed .
출력
For each query of the third type, output a single line with the answer.