##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Root the tree at vertex .
Consider any valid sequence of operations that deletes all vertices. Each operation deletes a set of currently present vertices whose labels form a consecutive set. So the whole process partitions the labels into consecutive intervals, because every deleted set is consecutive, and deleted sets are disjoint, and their union is all vertices.
Now take any interval from such a partition, and look at the induced subgraph on vertices inside the original tree. Because the original graph is a tree, the induced subgraph is a forest, so it consists of some connected components.
Pick one connected component of this induced subgraph. Let in the rooted tree. Among all components of the interval, choose the component whose has maximum depth, meaning it is the lowest LCA.
Claim: for this chosen component, is exactly a subtree of restricted to the still remaining vertices of the interval, so it can be deleted by one operation by choosing vertex .
Reason: All vertices of lie in the subtree of by definition of LCA. If there were a vertex in the subtree of that is inside the interval but not in , then would be separated from only by vertices outside the interval. That would force the induced subgraph to have another component whose LCA is strictly below , contradicting the choice of as having the lowest LCA.
So in every interval , if its induced subgraph is connected, then it can be deleted in one operation by choosing . Therefore the problem is equivalent to partitioning into intervals such that each interval induces a connected subgraph.