DSU - MarisaOJ: Marisa Online Judge

DSU

Time limit: 1000 ms
Memory limit: 256 MB
Given a graph of $n$ vertices and no edge. There are $q$ queries of either form: - `1 u v` add an edge between $u$ and $v$. - `2 u v` determine whether $u$ and $v$ are connected. ### Input - The first line contains 2 integers $n, q$. - The next $q$ lines, each line contains 3 integers $t, u, v$, a query. ### Output - For each query of type $2$, print `YES` if $u$ and $v$ are connected, otherwise print `NO`. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le u, v \le n$. ### Example Input: ``` 6 5 1 1 2 1 1 3 2 2 3 1 5 6 2 4 5 ``` Output: ``` YES NO ```