6.Longest path in an undirected tree

Spoj Question

Longest path 5 (node 5 to node 7)

Solution : (Using two BFS)

First BFS to find an endpoint of the longest path and second BFS from this endpoint to find the actual longest path.

Last updated

Was this helpful?