report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Fatal meal - FlandreOJ: Flandre Online Judge

Fatal meal

Time limit: 1000 ms
Memory limit: 256 MB
Marisa is conducting research on $n$ ingredients used in cooking, which can be categorized into two groups, Group $A$ and Group $B$. It is important to note that using two ingredients from different groups in a meal can be fatal. There are $q$ events of two types that Marisa encounters: - `1 u v`: Marisa realizes that ingredient $u$ and ingredient $v$ belong to different groups. - `2 u v`: Marisa questions whether it is safe to use ingredient $u$ and ingredient $v$ together in a meal, based on the information she has gathered so far. Help Marisa answer her questions! ### Input - The first line contains two integers $n,q$. - The next $q$ lines, each line contains three integers represent an event. It is guaranteed that all events are valid, there is no ingredient belong to both groups. ### Output - For each event of type two, print: + `FATAL` if two ingredients belong to different group. + `SAFE` if two ingredients belong to the same group. + `DUNNO` if there is not enough information to conclude. ### Constraints - $1 \le n,q \le 10^5$. - $1 \le u, v \le n$. ### Example Input: ``` 3 5 2 1 2 1 1 2 2 1 2 1 2 3 2 1 3 ``` Output: ``` DUNNO FATAL SAFE ```
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
Graph
DSU
Rating 1600
Solution (1) Solution