Legendary_Expert's blog

By Legendary_Expert, history, 7 years ago, In English

problem link: http://www.spoj.com/problems/FOXLINGS/en/

AC code: https://ideone.com/eLzUiU WA code: https://ideone.com/Z7d6qy

In my WA code i declared- ll node, edge, par[300005]; Same code I declared like- ll par[300005], node, edge; and got AC...

I can't figure out what's the difference between these two declaration..help please.

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

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

It might come down to line 37

for(int i = 1; i <= 300005; i++){ par[i] = i; }

You have only reserved the memory for 0 to 300004 with your ll par[300005] declaration so the code could overwrite other variables you have used and lead to unpredictable results. See if the WA case works if you change the i<=300005 to i<300005.

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

    But in my AC code I used the same i<=300005... got ac just by changing (ll par[300005], node, edge;) from (ll node, edge, par[300005];) Can you tell me why this happened. This declaration should also get WA if there was any unpredictable results issue. :/

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      That's what unpredictable means. It isn't guaranteed to fail in predictable manner.