Facing issue while solving Ada and Apple on spoj

Revision en6, by light.yagami01, 2020-08-29 10:24:20

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...

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English light.yagami01 2020-08-29 10:24:20 546
en5 English light.yagami01 2020-08-28 23:40:38 16
en4 English light.yagami01 2020-08-28 23:39:59 12
en3 English light.yagami01 2020-08-28 23:39:08 10
en2 English light.yagami01 2020-08-28 23:38:38 2825
en1 English light.yagami01 2020-08-28 23:34:58 3097 Initial revision (published)