Problem list
Log in
#r03329 · Online Judge > GoldOJ

Disjoint Sets

Gold V 2.0 s 256 MB

There are $N$ students. Process $Q$ operations. 0 a b makes $a$ and $b$ friends (merging their groups). 1 a b asks whether $a$ and $b$ are in the same group; print YES or NO.

Input

First line $N$ and $Q$; then $Q$ lines each T a b ($1 \le a, b \le N$, $T \in {0, 1}$).

Output

For every type-$1$ operation print YES or NO on its own line.

Example 1

Input
7 8
0 1 3
1 1 7
0 7 6
1 7 1
0 3 7
0 4 2
0 1 1
1 1 6
Output
NO
NO
YES
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code