SZTG#L#SP1437. PT07Z - Longest path in a tree

提交2 通过1
通过率50%
时间限制181ms
内存限制512MiB

题目描述

PT07Z - Longest path in a tree

题目描述

You are given an unweighted, undirected tree. Write a program to output the length of the longest path (from one node to another) in that tree. The length of a path in this case is number of edges we traverse from source to destination.

输入格式

The first line of the input file contains one integer NN --- number of nodes in the tree (0<N1040< N \le 10^4). Next N1N-1 lines contain N1N-1 edges of that tree --- Each line contains a pair (u,v)(u,v) means there is an edge between node uu and node vv.

输出格式

Print the length of the longest path on one line.

输入样例 #1

3
1 2
2 3

输出样例 #1

2

输入样例 #2

3
1 2
2 3

输出样例 #2

2

输入样例 #3

3
1 2
2 3

输出样例 #3

2

数据范围

The first line of the input file contains one integer NN --- number of nodes in the tree (0<N1040< N \le 10^4). Next N1N-1 lines contain N1N-1 edges of that tree --- Each line contains a pair (u,v)(u,v) means there is an edge between node uu and node vv.