Tornad0's blog

By Tornad0, history, 8 years ago, In English

Hi all,

I have difficulty on a problem on codeforces http://codeforces.net/problemset/problem/691/D

my submission is : http://codeforces.net/contest/691/submission/19308291

I think my idea is right, I used dsu to group several numbers and downsort numbers inside the groups. But I don't know why I am still wrong answer at test21. The idea is simple, but I can't find what's wrong. Anyone please help me, thanks:D

How to find bugs when you think your algorithms and implementation is correct,BTW?

Edit: Bug found:)))

I should calculate p[i]=parent(i) before I use p[i] . I thought it was automatically done by merging, however it is not :DDDD

  • Vote: I like it
  • -8
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Here is AC version of your submission. You should re-check the parent of every node.