Блог пользователя kevin9807

Автор kevin9807, история, 5 лет назад, По-английски

Problem link is here https://codeforces.com/contest/1167/problem/C

I used disjoint union but don't know why the size array converts to zero entry in test case 3 although I initiated it to 1 and did only addition. Thank You.

https://codeforces.com/contest/1167/submission/54618835

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Do not reconnect two people who are already in the same connected component. Only connect them if they are not already connected. You can easily check this by the find operation.

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You're merging two sets even when they represent the same set. I added two lines to your code and it gets accepted.