Disjoint Sets Union
Very easy
Execution time limit is 2 seconds
Runtime memory usage limit is 128 megabytes
Implement disjont sets union data structure. You have to perform queries of two types:
union u v - unite two sets that contain u and v respectively;
get u v - check that two elements u and v belong to the same set.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 5 * 10^5
) - the number of elements and the number of queries. Next m lines contain queries, one per line.
For a query union the line looks like union u v (1 ≤ u, v ≤ n).
For a query get the line looks like get u v (1 ≤ u, v ≤ n).
Output
Print the result of each query get one per line in the respected order: "YES", if the elements belong to the same set, and "NO" otherwise.
Examples
Input #1
Answer #1
Submissions 337
Acceptance rate 45%