atcoder#ARC088D. [ARC088F] Christmas Tree

[ARC088F] Christmas Tree

Score : 900900 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 NN vertices numbered 11 through NN and N1N-1 edges, whose ii-th edge (1iN1)(1\leq i\leq N-1) connects Vertex aia_i and bib_i.

He would like to make one as follows:

  • Specify two non-negative integers AA and BB.
  • Prepare AA Christmas Paths whose lengths are at most BB. Here, a Christmas Path of length XX is a graph with X+1X+1 vertices and XX edges such that, if we properly number the vertices 11 through X+1X+1, the ii-th edge (1iX)(1\leq i\leq X) will connect Vertex ii and i+1i+1.
  • Repeat the following operation until he has one connected tree:- Select two vertices xx and yy that belong to different connected components. Combine xx and yy into one vertex. More precisely, for each edge (p,y)(p,y) incident to the vertex yy, add the edge (p,x)(p,x). Then, delete the vertex yy and all the edges incident to yy.
  • Select two vertices xx and yy that belong to different connected components. Combine xx and yy into one vertex. More precisely, for each edge (p,y)(p,y) incident to the vertex yy, add the edge (p,x)(p,x). Then, delete the vertex yy and all the edges incident to yy.
  • Properly number the vertices in the tree.

Takahashi would like to find the lexicographically smallest pair (A,B)(A,B) such that he can make a Christmas Tree, that is, find the smallest AA, and find the smallest BB under the condition that AA is minimized.

Solve this problem for him.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1ai,biN1 \leq a_i,b_i \leq N
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

:

aN1a_{N-1} bN1b_{N-1}

Output

For the lexicographically smallest (A,B)(A,B), print AA and BB 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