arnav2004's blog

By arnav2004, history, 2 years ago, In English

I was solving this problem Problem Link

Here is my code

Now I don't want to know the logic of how to solve the problem or whether my logic is wrong or not.

It's just that when I am compiling this code is giving RE (Specifically : Runtime error: exit code is 2147483647)

Now when I comment out the line in which I unite two sets (Mentioned in the code), it does not give RE.

But I don't know how can my unite function be wrong(It's just merging two sets [DSU]).

Can anyone tell me the flaw?

EDIT : Found the error. Tbh it was a silly one. In my unite function when (p[x] != x) I call the function again with the same argument instead of p[x].

  • Vote: I like it
  • +9
  • Vote: I do not like it

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

Did you make sure to set p[i] = i initially? I can only see all pi values initialized to 0 which means the find method goes into an infinite loop — I have made this mistake many times before :) but you should know how to debug it using print statements

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yes. I have set them to the corresponding values initially (using iota function which does the same). I have tried everything to debug but am just not able to find the error :(

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

Auto comment: topic has been updated by arnav2004 (previous revision, new revision, compare).