When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

kevin9807's blog

By kevin9807, history, 5 years ago, In English

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

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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