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

kingofnumbers's blog

By kingofnumbers, history, 9 years ago, In English

hello guys

I was trying to solve problem EAGLE1 in spoj OJ

the problem gives you a weighted tree and ask you for each node , find farthest node from it

this is very standard dp problem but my code strangely always take runtime error , although I tried different coding styles.

I thought maybe there's something wrong with test cases but I tried to write code that check the validity of test case before processing it but it showed that nothing wrong with the test cases

I'm seeking for help to explain what's happening , here's my code

thank you in advance

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

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

looks like a stack overflow

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

    Does spoj have stack size limit?

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

      I have got the same problem while implementing HLD. Try a non-recursive dfs, it works for me

»
9 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Adding #pragma comment(linker, '/STACK:200000') to the top of your code gets it accepted :P

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

    I've always thought that spoj doesn't limit stack size, thank you for help :)

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Can someone please help me find out where I am wrong code . Thanks in advance