QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#9713. Kill the tree

统计

Given a tree with $N$ vertices(vertices are numbered from $1$ to $N$), where 1 is the root of the tree. The weight of the edges on the tree is 1.

Define $d(u, v)$ as the distance between vertex $u$ and $v$.

Define $c(w)=\sum \limits_{v \in T} d(w, v)$. We call a vertex $w$ on tree $T$ the critical point, if $c(w) \le \min \limits_{u \in T} c(u)$

Now, for all $i \in [1, N]$, you must print the "critical points" of the subtree rooted at vertex $i$.

Input

The first line of the input contains an integer $N$ denotes the number of vertices of the tree.

Then, $N - 1$ line follows, the $i^{th}$ line contains two integers $a_i, b_i$, denotes the $i^{th}$ edge on the tree.

  • $1 \le N \le 2 \times 10^5$
  • $1 \le a_i, b_i \le N$
  • The input is a tree

Output

Output $N$ lines.

On the $i^{th}$ line, output the "critical points" of the subtree rooted at vertex $i$ in ascending order. Two integers in one line must be separated by one space.

Sample Input

4
1 2
2 3
2 4

Sample Output

2
2
3
4

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.