White-Black Balanced Subtrees
MediumRating 1300CodeforcesMixed Practice
Approach hintTry it first, then revealHide
For every vertex, compute the white count minus the black count of its subtree, children before parents, and count the vertices where it is zero. Parents have smaller indices, so a backward loop can replace recursion.