atcoder#ABC183F. [ABC183F] Confluence
[ABC183F] Confluence
Score : points
Problem Statement
students are about to go to school. Student belongs to Class .
After leaving home, each student will head to school while repeatedly joining up with a group of other students. Once students join up with each other, they will not separate.
You will be given queries that should be processed in order. There are two kinds of queries, in the following formats, that mean the following:
1 a b
: The group containing Student and the group containing Student merges. (If they are already in the same group, nothing happens.)2 x y
: You are asked to find the number of students belonging to Class who are already in the same group as Student (including Student ) at the time of this query.
Constraints
- In a query in the format
1 a b
, . - All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answers to the queries in the format 2 x y
, each in its own line, in order.
5 5
1 2 3 2 1
1 1 2
1 2 5
2 1 1
1 3 4
2 3 4
2
0
At the time of the -rd query, Student has joined up with Student and . Among these three students, two belong to Class .
At the time of the -th query, Student has joined up with Student . Among these two students, none belongs to Class .
5 4
2 2 2 2 2
1 1 2
1 1 3
1 2 3
2 2 2
3
There may be queries in the format 1 a b
for students who already belong to the same group.
12 9
1 2 3 1 2 3 1 2 3 1 2 3
1 1 2
1 3 4
1 5 6
1 7 8
2 2 1
1 9 10
2 5 6
1 4 8
2 6 1
1
0
0