If the child is Adding positively to difference , we include it in the answer Otherwise , we leave the sub - tree and include 0 ( nothing ) in the answer
answer [ node ] += Math . Max ( answer [ u ] , 0 ) ; } } static int maxDiff ( List < int > [ ] tree , int [ ] colour , int N ) { int [ ] answer = new int [ N + 1 ] ;