题库练习 The Winds of Winter
← 上一题 下一题 →

A10823 | The Winds of Winter

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Given a rooted tree with $n$ nodes. The Night King removes exactly one node from the tree and all the edges associated with it. Doing this splits the tree and forms a forest. The node which is removed is not a part of the forest.

The root of a tree in the forest is the node in that tree which does not have a parent. We define the strength of the forest as the size of largest tree in forest.

Jon Snow wants to minimize the strength of the forest. To do this he can perform the following operation at most once.

He removes the edge between a node and its parent and inserts a new edge between this node and any other node in forest such that the total number of trees in forest remain same.

For each node $v$ you need to find the minimum value of strength of the forest formed when node $v$ is removed.

输入格式

The first line of the input contains an integer $n$ ( $1<=n<=10^{5}$ ) — the number of vertices in the tree. Each of the next $n$ lines contains a pair of vertex indices $u_{i}$ and $v_{i}$ ( $1<=u_{i},v_{i}<=n$ ) where $u_{i}$ is the parent of $v_{i}$ . If $u_{i}=0$ then $v_{i}$ is the root.

输出格式

Print $n$ line each containing a single integer. The $i$ -th of them should be equal to minimum value of strength of forest formed when $i$ -th node is removed and Jon Snow performs the operation described above at most once.

输入输出样例

输入 #1
10
0 1
1 2
1 3
1 4
2 5
2 6
3 7
4 8
4 9
5 10
输出 #1
3
4
5
5
5
9
9
9
9
9
输入 #2
2
2 1
0 2
输出 #2
1
1
C++ 编辑器
输入
输出