Typical ICPC Problem#10827

Typical ICPC Problem (Розбір)

For a tree, it's a pretty well-known problem, but let's remind the solution.

Let's process the nodes in order from the smallest weight to the largest, keeping the current right end . For each node with weight from to , we will also keep t