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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
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).