Bitset Master
Time limit6sMemory limit512 MB
Each vertex starts with its own set, edge operations merge the sets at both endpoints, and queries count how many sets contain a given vertex.
- Level
Hard9 of 10
- Topics
- Tree, Union-find, Divide and conquer
- Solved
- No attempts yet
Problem
It is well known in China that algorithms can pass a problem with easily.
You are given a tree with vertices and edges . Each vertex has a set . Initially .
There are two types of operations.
- "1 u": output the number of sets () that contain .
- "2 p": take the sets and , where is the -th edge, and assign to both of them.
You need to perform operations. Output the answer for each operation of the first kind.
The time limit is 6000 ms and the memory limit is 512 MB.
Input
The first line contains two integers and (, ).
Each of the following lines contains two integers and describing an edge ().
Each of the following lines contains two integers and describing an operation (, ).
Output
For each operation of the first kind, output an integer on a separate line.