Codeforces Round 300
E
Demiurges Play Again
Codeforces
2200
原题
← DF →
翻译中…

Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game.

翻译中…

There is a rooted tree on $*n*$ nodes, $*m*$ of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of the tree integers from 1 to $*m*$ are placed in such a way that each number appears exactly in one leaf.

翻译中…

Initially, the root of the tree contains a piece. Two players move this piece in turns, during a move a player moves the piece from its current nodes to one of its children; if the player can not make a move, the game ends immediately. The result of the game is the number placed in the leaf where a piece has completed its movement. The player who makes the first move tries to maximize the result of the game and the second player, on the contrary, tries to minimize the result. We can assume that both players move optimally well.

翻译中…

Demiurges are omnipotent, so before the game they can arbitrarily rearrange the numbers placed in the leaves. Shambambukli wants to rearrange numbers so that the result of the game when both players play optimally well is as large as possible, and Mazukta wants the result to be as small as possible. What will be the outcome of the game, if the numbers are rearranged by Shambambukli, and what will it be if the numbers are rearranged by Mazukta? Of course, the Demiurges choose the best possible option of arranging numbers.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ — the number of nodes in the tree ($1 ≤ *n* ≤ 2·10^{5}$).

翻译中…

Each of the next $*n* - 1$ lines contains two integers $*u*_{*i*}$ and $*v*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$) — the ends of the edge of the tree; the edge leads from node $*u*_{*i*}$ to node $*v*_{*i*}$. It is guaranteed that the described graph is a rooted tree, and the root is the node 1.

翻译中…

Output

翻译中…

Print two space-separated integers — the maximum possible and the minimum possible result of the game.

翻译中…

Note

翻译中…

Consider the first sample. The tree contains three leaves: 3, 4 and 5. If we put the maximum number 3 at node 3, then the first player moves there and the result will be 3. On the other hand, it is easy to see that for any rearrangement the first player can guarantee the result of at least 2.

翻译中…

In the second sample no matter what the arragment is the first player can go along the path that ends with a leaf with number 3.

翻译中…

样例

Input #1
5
1 2
1 3
2 4
2 5
Output #1
3 2
InputCopy OutputCopy
Input #2
6
1 2
1 3
3 4
1 5
5 6
Output #2
3 3
InputCopy OutputCopy
题目信息
题号
538E
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
动态规划
数学
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。