Need help with forgotten tree problem JUNE19

How to solve the problem forgetten tree.
My approach was recursively solve the problem:

   for i=l to r:
     if l to r in subtree of i:
         i is the root of subtree(l,r) and p is the parent of i
        solve for(l,i-1) and (i+1,r)

It passed first two subtasks.What is the correct way to solve the problem

Official Editorial

1 Like

Thanks , I didn’t see that the editorial came