3497. Find the Last Marked Nodes in Tree

Hard
Tree
Depth-First Search

Description

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.

Statistics

Acceptance
55.3%
Submissions
1,084
Accepted
599