Problem 3949 · Hard

Subtree Inversion Sum II

In a tree rooted at node 0, inverting a node multiplies every value in its subtree by -1, and any two inverted nodes must be at least k edges apart. Choose the inverted nodes to make the total of all values as large as possible.

Open the interactive visualisation