report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Traffic system - MarisaOJ: Marisa Online Judge

Traffic system

Time limit: 1000 ms
Memory limit: 256 MB
A country has $n$ cities. There are two ways to move between two cities, using subway or using road. Initially, there are no connection between any two cities. There are $q$ queries of either form: * `1 u v`: Build a road between $u$ and $v$. * `2 u v`: Build a subway system between $u$ and $v$. After each query, determine if the traffic system in this country is good. The system is called good if for every pair of cities $i$ and $j$, if one can travel from $i$ to $j$ using subway then he can also use road to travel, and vice versa. ### Input - The first line contains two integers $n, q$. - The next $q$ lines, each line is a query. ### Output - For each query, if the system is good, print `YES`, otherwise print `NO`. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le u, v \le n$. ### Example Input: ``` 2 2 1 1 2 2 1 2 ``` Output: ``` NO YES ```
Hash a set
Prefix equality
Good subarray
Brewing potion 6
Mino
Traffic system
Odd
Topic
DSU
Hashing
Rating 2000
Solution (0) Solution