CodeTON Round 5 (Div. 1 + Div. 2, Rated, Prizes!)
F
Tenzing and Tree
Codeforces
2500
原题
← EG →
翻译中…

Tenzing has an undirected tree of $n$ vertices.

翻译中…

Define the value of a tree with black and white vertices in the following way. The value of an edge is the absolute difference between the number of black nodes in the two components of the tree after deleting the edge. The value of the tree is the sum of values over all edges.

翻译中…

For all $k$ such that $0 \leq k \leq n$, Tenzing wants to know the maximum value of the tree when $k$ vertices are painted black and $n-k$ vertices are painted white.

翻译中…

Input

翻译中…

The first line of the input contains a single integer $n$ ($1\leq n\leq 5000$) — the number of vertices.

翻译中…

The following $n-1$ lines of the input contains $2$ integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n, u_i \neq v_i$) — indicating an edge between vertices $u_i$ and $v_i$. It is guaranteed that the given edges form a tree.

翻译中…

Output

翻译中…

Output $n+1$ numbers. The $i$-th number is the answer of $k=i-1$.

翻译中…

Note

翻译中…

Consider the first example. When $k=2$, Tenzing can paint vertices $1$ and $2$ black then the value of edge $(1,2)$ is 0, and the values of other edges are all equal to $2$. So the value of that tree is $4$.

翻译中…

样例

Input #1
4
1 2
3 2
2 4
Output #1
0 3 4 5 6
InputCopy OutputCopy
Input #2
1
Output #2
0 0
InputCopy OutputCopy
题目信息
题号
1842F
时间限制
2 s
内存限制
512 MB
标签
DFS 及类似
贪心
最短路
排序
树

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