~/algor $ cat problems/graf-qurilish-sorovlari
Road building queries
Medium
1000 ms
128 MB
53%
A country has $n$ cities, and initially there are no roads between them. $q$ queries arrive one after another:
1 u v— a two-way road is built between cities $u$ and $v$;2 u v— can one get from city $u$ to city $v$ along the existing roads?
Answer every query of the second type.
Input
The first line contains two positive integers: $n$ and $q$. Each of the next $q$ lines contains three numbers: $t$, $u$, $v$ — a query.
Output
For each query of type 2, on a separate line, YES or NO.
Note
$1 \le n, q \le 10^{5}$
$t \in \{1, 2\}$
$1 \le u, v \le n$
There is at least one query of type 2.
Examples
Input #1
5 6 1 1 2 2 1 3 1 2 3 2 1 3 1 4 5 2 3 5
Output #1
NO YES NO
Input #2
2 2 2 1 1 2 1 2
Output #2
YES NO