Parsa's Humongous Tree
MediumRating 1600CodeforcesAdvanced Trees (BST, LCA, Tree DP)
Approach hintTry it first, then revealHide
Some optimal assignment uses only interval endpoints, so each vertex takes either l or r. Run a tree DP with two states per vertex, one for each endpoint choice.