Unite to Survive
InterviewTime limit2sMemory limit1024 MB
Given N sets, process commands that merge set b into set a and empty set b, and print the size of a queried set.
- Level
Medium6 of 10
- Topics
- Hash map, Union-find, Implementation
- Solved
- No attempts yet
Problem
Given sets , process commands as follows.
1 a b: Replace with , and replace with the empty set. (; )2 a: Print the size of . ()
Input
The first line contains and . ()
Each of the next lines describes . The line starts with its size , followed by the elements of . (; ; for all )
Each of the next lines contains one command described above. All input numbers are integers, and at least one command 2 a is given.
Output
For each command 2 a, print the result on its own line.