Problem 3544 · Hard

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.

Open the interactive visualisation