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 ) ; } } function maxDiff ( tree , colour , N ) { var answer = Array ( N + 1 ) . fill ( 0 ) ;