Hello everyone,
I was trying to solve the question on Spoj named Ada and Apple.
Link to the problem: https://www.spoj.com/problems/ADAAPPLE/
Link to the solution I wrote: http://p.ip.fi/2Gz1
I've tried to explain the code via comments and Here's my approach
As stated in Question, I am supposed to check whether one can move from one node to another. It's possible only if all the nodes appearing in the path should be owned by the same owner. (Owner is either 0/1)
Idea is to calculate sum of all the nodes in path. if sum equals to the path length or 0 then it's possible to move otherwise not.
I've used 1. Segment tree to calculate the range sum 2. path length (Number of nodes in a path) is counted using LCA
I am getting WA after test case 15, I don't know what's wrong...
Help me out...
Happy coding...







