3313. Find the Last Marked Nodes in Tree
TreeDepth-First Search
Hints
Hint 1
We need to calculate the height of tree when rooted at each node.
Hint 2
Find a diameter using two DFS.
Hint 3
The farthest node from each node must be one of the endpoints of the diameter.
Hint 4
The last marked node will be one of the end of the diameter, whichever is more distant.
Preparing judge…