While it succeeds on the sample test case, it fails on all the rest of the test cases (wrong answer). It uses an iterative Euler tour and calculates the XOR of the path to each of the nodes along with the LCA for the answer with a segment tree.
Yeah… turns out (after copy pasting some other USACO sample trees) that the problem lied in generating the Euler tour. I wasn’t adding the leaf nodes twice, and doing that made it pass just barely under the time limit, like 3988 ms.
Thanks so much!
But I have a nagging feeling that this could be made much faster… any suggestions? (Fixed code is here)