Thanx
For last sum ,we consider each node as B type node,obviously now if we wanna find C node for that node v ,we should just take maximum in subtree of v.
Now v is B node,max is C node
So only thing left is A node,if we have a map containing elements of path root to v,then we can find easily the largest value less than v among the parents of v,which is A.
These all can be done in a single dfd(i dont know y i used 2,should’ve done with 1).
Solution: