You are given nodes that are completely separated. You must support the following operations:
1 a b
Add an edge between node and node . . Note that it is not guaranteed node and node are not connected beforehand.2 a b
Output whether two nodes are connected. Two nodes are connected if there is a path from the first node to the second.
There will be of these operations.
Input Specification
The first line will integers, .
The next lines will each contain a operation as defined above.
Output Specification
For each type operation, print YES
if the two nodes are connected, and NO
otherwise. (Exact capitalization).
Subtasks
Subtask 1 [20%]
Subtask 2 [80%]
No further constraints.
Sample Input
4 5
2 1 3
1 1 2
1 2 4
2 1 4
2 3 4
Sample Output
NO
YES
NO
Comments