Disjoint Set Operations

Time limit2sMemory limit128 MB

Problem

Initially, each integer from $0$ through $n$ belongs to its own separate set. In other words, the initial sets are $\{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 $n$ and $m$. Here, $m$ is the number of operations to process.

Each of the next $m$ lines contains one operation.

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

Output

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

Constraints

  • $1 \le n \le 1\,000\,000$
  • $1 \le m \le 100\,000$
  • $0 \le a, b \le n$
  • $a$ and $b$ are integers.
  • $a$ and $b$ may be equal.