TTC '18 Contest 1 P4 - A Very Interesting Problem
View as PDFYou are given  nodes that are completely separated. You must support the following operations:
1 a bAdd an edge between nodeand node
.
. Note that it is not guaranteed node
and node
are not connected beforehand.
2 a bOutput whether two nodesare 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