cho.sh
Notes
Loading...

Disjoint Set Operations

Time limit

2s

Memory limit

128 MB

Problem

Initially, each integer from 000 through nnn belongs to its own separate set. In other words, the initial sets are 0,1,2,dots,n\\{0\\}, \\{1\\}, \\{2\\}, \\dots, \\{n\\}0,1,2,dots,n.

You must process two kinds of operations. One operation merges the sets containing two given elements, and the other checks whether two given elements are in the same set.

Write a program that processes all operations in order.

Input

The first line contains two integers nnn and mmm. Here, mmm is the number of operations to process.

Each of the next mmm lines contains one operation.

  • 0 a b: merge the set containing aaa and the set containing bbb.
  • 1 a b: check whether aaa and bbb belong to the same set.

Output

For each operation of the form 1 a b, print YES if aaa and bbb are in the same set, and NO otherwise. Print each answer on its own line.

Constraints

  • 1≤n≤1,000,0001 \le n \le 1\\,000\\,0001≤n≤1,000,000
  • 1≤m≤100,0001 \le m \le 100\\,0001≤m≤100,000
  • 0≤a,b≤n0 \le a, b \le n0≤a,b≤n
  • aaa and bbb are integers.
  • aaa and bbb may be equal.