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 ] += max ( answer [ u ] , 0 ) ; } } int maxDiff ( vector < int > tree [ ] , int colour [ ] , int N ) { int answer [ N + 1 ] ; memset ( answer , 0 , sizeof ( answer ) ) ;