EILGPTH - Longest paths
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 of ~n~ nodes. Your task is to find the longest paths, then print out the smallest vertex in the paths and their length.
Input
- The first line contains an integer ~n~ ~(0 < n ≤ 10^5)~.
- Each of the next ~n-1~ lines contains two integers ~a, b~ representing an edge that connects vertex ~a~ and vertex ~b~ ~(0 ≤ a, b < n)~.
Output
- The smallest vertex and the length of the longest paths.
Example Input
9
6 1
6 2
4 3
2 4
1 5
0 2
6 7
7 8
Example Output
1 5
Note
- There are 2 longest paths: (3 – 4 – 2 – 6 – 1 – 5), (3 – 4 – 2 – 6 – 7 – 8)
- https://drive.google.com/file/d/1X8C5RjabX7cef0YqRn6m79kVTQ81m5AP/view?usp=sharing
Bình luận