~/algor $ cat problems/daraxt-diametri
Tree diameter
Medium
1000 ms
128 MB
60%
A tree (a connected acyclic graph) with $n$ vertices and $n - 1$ edges is given. The vertices are numbered from $1$ to $n$. Find the diameter of the tree — the number of edges on the longest simple path between two vertices.
Input
The first line contains a positive integer $n$. Each of the next $n - 1$ lines contains two positive integers: $u$ and $v$ — the vertices joined by an edge.
Output
One integer — the diameter of the tree.
Note
$1 \le n \le 2 * 10^{5}$
$1 \le u, v \le n$
Examples
Input #1
5 1 2 1 3 2 4 2 5
Output #1
3
Input #2
4 1 2 2 3 3 4
Output #2
3