Hi Folks,
I wrote the this solution for this Tree Constructing but i kept getting runtime error during the contest. Though i managed to get my solution accepted by changing few things but still did not understand why i was getting runtime error. Can anybody help here ?
Why don't you explain what you changed to solve runtime error.
The only difference in this accepted solution and this runtime exception solution is the order in which i have define vector<pair<int, int>> e;
Below your submission you can see in which case your solution fails and a hint of the RTE. In this case the message is:
Diagnostics
Diagnostics detected issues [cpp.clang++-diagnose]: p71.cpp:120:58: runtime error: index -1094795586 out of bounds for type 'int [400010]' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior p71.cpp:120:58 in
Check this part: index -1094795586 out of bounds for type 'int [400010]'
You're trying to acces in to a negative position.
By your code, i can say is this one: int deg[4 * 100000 + 10];
I hope it will help you.