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 ) NEW_LINE def maxDiff ( tree , colour , N ) : NEW_LINE answer = [ 0 for _ in range ( N + 1 ) ] NEW_LINE