Military Problem
MediumRating 1600CodeforcesAdvanced Trees (BST, LCA, Tree DP)
Approach hintTry it first, then revealHide
Record one DFS order that visits children in increasing index order, together with every subtree size. The subtree of u is a contiguous block starting at its position, so each query is a single lookup.