atcoder#ARC088D. [ARC088F] Christmas Tree
[ARC088F] Christmas Tree
Score : points
Problem Statement
Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc.
A Christmas Tree is a tree with vertices numbered through and edges, whose -th edge connects Vertex and .
He would like to make one as follows:
- Specify two non-negative integers and .
- Prepare Christmas Paths whose lengths are at most . Here, a Christmas Path of length is a graph with vertices and edges such that, if we properly number the vertices through , the -th edge will connect Vertex and .
- Repeat the following operation until he has one connected tree:- Select two vertices and that belong to different connected components. Combine and into one vertex. More precisely, for each edge incident to the vertex , add the edge . Then, delete the vertex and all the edges incident to .
- Select two vertices and that belong to different connected components. Combine and into one vertex. More precisely, for each edge incident to the vertex , add the edge . Then, delete the vertex and all the edges incident to .
- Properly number the vertices in the tree.
Takahashi would like to find the lexicographically smallest pair such that he can make a Christmas Tree, that is, find the smallest , and find the smallest under the condition that is minimized.
Solve this problem for him.
Constraints
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
:
Output
For the lexicographically smallest , print and with a space in between.
7
1 2
2 3
2 4
4 5
4 6
6 7
3 2
We can make a Christmas Tree as shown in the figure below:
8
1 2
2 3
3 4
4 5
5 6
5 7
5 8
2 5
10
1 2
2 3
3 4
2 5
6 5
6 7
7 8
5 9
10 5
3 4