kevin9807's blog

By kevin9807, history, 3 weeks 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

»
3 weeks 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.

»
3 weeks 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.