Problem Description
Loading...
Problem Analysis
Given a tree, find the maximum distance between two nodes in the tree
that is, find the Tree Diameter
Idea: from any node, find its farthest node u; then from u find its farthest node v; the distance between u and v is the maximum distance.
You can use DFS||BFS to search
since the time complexity is similar and DFS is more concise
so DFS is used here
The tree is stored using an Adjacency List
cpp
| |