Subtree Inversion Sum
Inverting a node flips its whole subtree, so a tree DP tracks the distance to the nearest inverted ancestor and the parity of inversions above.
Inverting a node flips its whole subtree, so a tree DP tracks the distance to the nearest inverted ancestor and the parity of inversions above.