Problem 3787 · Medium

Find Diameter Endpoints of a Tree

Two breadth-first searches locate a farthest pair in a tree: search from any node, then from the farthest one.

Open the interactive visualisation