#C10892. Teleportation System
Teleportation System
Teleportation System
In this problem, you are given a set of operations on a teleportation system. There are two types of operations:
-
Union Operation (1 a b): Create a teleportation gate connecting point (a) and point (b). This operation effectively merges the groups containing (a) and (b).
-
Query Operation (2 a b): Check if point (a) can teleport to point (b) (i.e. if they are in the same connected component).
You must process the operations sequentially and output the result of each query. Use the (\textbf{union-find}) data structure (also known as disjoint set union) to efficiently support these operations.
The operations are given via standard input (STDIN) and the results of the queries must be printed to standard output (STDOUT).
inputFormat
The first line contains an integer (n) (the number of operations). Each of the next (n) lines contains three integers:
- The first integer indicates the type of operation (1 for union, 2 for query).
- The next two integers (a) and (b) represent the points involved in the operation.
It is guaranteed that the points are positive integers.
outputFormat
For each query operation (operation type 2), output a single line containing either "YES" or "NO" depending on whether the two points are connected.## sample
6
1 1 2
1 2 3
2 1 3
1 4 5
2 1 5
2 4 5
YES
NO
YES
</p>