#P1842F. Tenzing and Tree

    ID: 9926 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>dfs and similargreedyshortest pathssortingstrees*2500

Tenzing and Tree

Description

Tenzing has an undirected tree of nn 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 kk such that 0kn0 \leq k \leq n, Tenzing wants to know the maximum value of the tree when kk vertices are painted black and nkn-k vertices are painted white.

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

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

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

Input

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

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

Output

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

Sample Input 1

4
1 2
3 2
2 4

Sample Output 1

0 3 4 5 6

Sample Input 2

1

Sample Output 2

0 0

Note

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