report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
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 ```
Disjoint Set Union (DSU)
DSU
Component sum
Minimum spanning tree
Parking
Remove edge
Yet another problem
Assignment query on tree
Watering
Minimum spanning tree 2
Fatal meal
Statement
All pairs
Query on tree
Minimum spanning tree 3
Topic
DSU
Rating 1000
Solution (0) Solution