EITREHE1 - Tree height
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Given a tree with ~N~ nodes which are numbered from ~0~ to ~N-1~. Root of tree is node numbered by ~0~. Caculate height of the tree.
Input
- The first line is an integer ~N~ ~(1 \le N \le 10^5)~.
- Each line in the next ~N - 1~ lines contains ~2~ integers ~u, v~, represeting an edge connecting vertex ~u~ and vertex ~v~.
Output
- An integer which is height of the given tree.
Sample Input
3
0 1
1 2
Sample Output
2
Bình luận