Problem 3313 · Hard

Find the Last Marked Nodes in Tree

Find the two ends of a longest path with two searches; for every node, the farther of those two ends is a last-marked node.

Open the interactive visualisation