LINK for the problem I am learning DSU and came up with this question but could not apply DSU. It will be of great help if someone tell the logic for solving this problem.
UPD 1 :solved the question LINK for answer
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
LINK for the problem I am learning DSU and came up with this question but could not apply DSU. It will be of great help if someone tell the logic for solving this problem.
UPD 1 :solved the question LINK for answer
Name |
---|
Good day to you!
Firstly, set all colors to "UNDEF" [for example -1] {uncolored} and build graph (for example with vectors [I assume you can do this, if not, ask more!]).
Now for each query of type 1, set color to "y" and iterate over all "neighbors" and check whether their color is same — in case of "yes", connect them with DSU.
The second query just ask if their DSU-component is same.
Since "he colors each node at most once" there is no problem with "erasing connections" (even though it would be solvable too, just much harder).
Good Luck!
Thanks
solved the question.
Hi ! Sorry if I'm late, but can you tell me how do you solve it without that condition "he colors each node at most once" ?
Hmm I got some doubts about it, because it is true that graph of "star-shape" with queries to the star (which means simple iteration over neighbors would time out) will "kill" it, but if it will be "reasonable" graph, then Link-Cut-Tree shall do it (instead of DSU).