Submit | All submissions | Best solutions | Back to list |
EILGPTH - Longest paths |
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 (0 < n ≤ 105).
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.
* There are 2 longest paths: (3 – 4 – 2 – 6 – 1 – 5), (3 – 4 – 2 – 6 – 7 – 8)
Example
https://drive.google.com/file/d/1X8C5RjabX7cef0YqRn6m79kVTQ81m5AP/view?usp=sharing
Input: 9 6 1 6 2 4 3 2 4 1 5 0 2 6 7 7 8 Output: 1 5
Added by: | Ha Minh Ngoc |
Date: | 2021-07-21 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: GOSU |