Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
We need to calculate the height of tree when rooted at each node.
Find a diameter using two DFS.
The farthest node from each node must be one of the endpoints of the diameter.
The last marked node will be one of the end of the diameter, whichever is more distant.