EIMAXHTR - The highest tree

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:
Hà Minh Ngọc
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Given a tree ~N~ vertices, numbered from ~0~ to ~N-1~. Find the vertex with the smallest index such that the height of the tree is greatest if the vertex  with the smallest is root

Input

  • The first line is an integer ~N~ ~(1 \le N \le 10^5)~.
  • The next ~N - 1~ lines contain ~2~ integers ~u~ ~v~, the connecting edge between vertex ~u~ and vertex ~v~.

Output

  • Print the vertex and maximum height

Example Input 1

3
0 1
1 2

Example Output 1

0 2

Example Input 2

4
0 1
0 2
2 3

Example Output 2

1 3

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.