eolymp
bolt
Try our new interface for solving problems
Problems

Disjoint Sets Union

Disjoint Sets Union

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 (1n, m5 * 105) - 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 (1u, vn).

For a query get the line looks like get u v (1u, vn).

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.

Time limit 2 seconds
Memory limit 128 MiB
Input example #1
4 4
union 1 2
union 1 3
get 1 4
get 2 3
Output example #1
NO
YES
Author Michael Medvediev