Getting WA in Wealth Disparity?

dfs
dps
graph

#1

I am attempting the [Wealth Disparity][1] problem but I am getting wrong ans.

[This][2] is link to my solution, anyone please help me in debugging what is wrong with my code.
[1]: https://www.codechef.com/INOIPRAC/problems/INOI1601
[2]: https://pastebin.com/6d0LSXej


#2

I think u’ve misread the question,we want max(diff(i-j) for all childs j of i) for all i


#3

@vivek_1998299

I have made an assumption which is, if ‘b’ is parent of ‘a’ and ‘x’ is the value which gave the maximum difference for ‘b’ then the maximum difference for ‘a’ will be given either by the sam value x i.e., x-A[a] or by A**-A[a] this could be summed up as diff[a]=max(x-A[a], A**-A[a]).

Let me know if anything is wrong with this assumption.


#4

U could just take min of subtree of i and subtract it from i


#5

@vivek_1998299

In problem statement it is said that wealth falls rapidly as one goes down the organizational tree but in the given test case the owner’s wealth is less then 4th employee. Can you please explain how this is possible.