TTC '18 Contest 2 P5 - A Hard Tree Problem

View as PDF

Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Given a tree containing N nodes, print the maximum depth of the tree if the tree can be rooted at any node.

The maximum depth of a tree rooted at a certain node u is defined as the maximal number of edges in the path that begins at u.

Input Specification

The first line will contain the integer N (1 \le N \le 10^5), the number of nodes.

The next N-1 lines will each contain 2 integers, a, b (1 \le a, b \le N), indicating nodes a and b are connected by a single edge. It is guaranteed the entire tree is connected.

Output Specification

On the first line, output 2 integers, the maximum depth of the tree, and the node to root the tree at. If there are multiple such nodes, print the one with the smallest index.

Sample Input

5
2 1
1 3
1 4
3 5

Sample Output

3 2

Explanation for Sample

If the tree was rooted at node 2, the maximum depth would be 3.


Comments

There are no comments at the moment.