287. Diameter of a Tree
MediumBFSTrees
The graph is a tree. Print its diameter: the number of edges on the longest path between two nodes.
Input format
Line 1: n Next n − 1 lines: u v
Output format
The diameter.
Example 1
Input
5 1 2 1 3 3 4 3 5
Output
3
Example 2
Input
1
Output
0
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…