33OJ
登录 注册

#ABC479E. 切边与累加 / Cut and Add

切边与累加 / Cut and Add

Problem Statement

There is a tree with NN vertices numbered 1,2,…,N1,2,\dots,N. Here, NN is odd.

The edges are also numbered 1,2,…,N−11,2,\dots,N-1, and edge ii connects vertices AiA_i and BiB_i.

Each vertex ii has a variable xix_i, and initially xi=0x_i=0 for every vertex ii.

Now, for i=1,2,…,N−1i=1,2,\dots,N-1 in this order, perform the following operation.

  • First, remove edge ii. As a result, the tree is split into two connected components.
  • For every vertex vv in the connected component containing more vertices, add ii to xvx_v.
    • Since NN is odd, the connected component containing more vertices is uniquely determined.
  • Finally, restore edge ii.

Find the values of the variables x1,x2,…,xNx_1,x_2,\dots,x_N of the vertices after all operations are performed.

Constraints

  • All input values are integers.
  • NN is an odd number satisfying 3≤N≤2×105−13 \le N \le 2 \times 10^5 - 1.
  • 1≤Ai<Bi≤N1 \le A_i < B_i \le N
  • The given graph is a tree.

Input

The input is given from Standard Input in the following format:

  • NN
  • A1A_1 B1B_1
  • A2A_2 B2B_2
  • ⋮\vdots
  • AN−1A_{N-1} BN−1B_{N-1}

Output

Output the final values of the variables in the following format:

  • x1x_1 x2x_2 …\dots xNx_N
5
2 4
1 5
1 4
1 3
10 6 6 7 8
  • For i=1i=1, the following operation is performed.
    • Removing edge 11 splits the tree into a connected component with vertex 22 and a connected component with vertices 1,3,4,51,3,4,5.
    • The larger one is the connected component with vertices 1,3,4,51,3,4,5, so 11 is added to all of their variables.
    • As a result, the values of the variables become (x1,x2,x3,x4,x5)=(1,0,1,1,1)(x_1,x_2,x_3,x_4,x_5)=(1,0,1,1,1).
    • Finally, edge 11 is restored.
  • For i=2i=2, the following operation is performed.
    • Removing edge 22 splits the tree into a connected component with vertex 55 and a connected component with vertices 1,2,3,41,2,3,4.
    • The larger one is the connected component with vertices 1,2,3,41,2,3,4, so 22 is added to all of their variables.
    • As a result, the values of the variables become (x1,x2,x3,x4,x5)=(3,2,3,3,1)(x_1,x_2,x_3,x_4,x_5)=(3,2,3,3,1).
    • Finally, edge 22 is restored.
  • For i=3i=3, the following operation is performed.
    • Removing edge 33 splits the tree into a connected component with vertices 2,42,4 and a connected component with vertices 1,3,51,3,5.
    • The larger one is the connected component with vertices 1,3,51,3,5, so 33 is added to all of their variables.
    • As a result, the values of the variables become (x1,x2,x3,x4,x5)=(6,2,6,3,4)(x_1,x_2,x_3,x_4,x_5)=(6,2,6,3,4).
    • Finally, edge 33 is restored.
  • For i=4i=4, the following operation is performed.
    • Removing edge 44 splits the tree into a connected component with vertex 33 and a connected component with vertices 1,2,4,51,2,4,5.
    • The larger one is the connected component with vertices 1,2,4,51,2,4,5, so 44 is added to all of their variables.
    • As a result, the values of the variables become (x1,x2,x3,x4,x5)=(10,6,6,7,8)(x_1,x_2,x_3,x_4,x_5)=(10,6,6,7,8).
    • Finally, edge 44 is restored.

The final values of the variables are (x1,x2,x3,x4,x5)=(10,6,6,7,8)(x_1,x_2,x_3,x_4,x_5)=(10,6,6,7,8).

3
1 2
2 3
2 3 1
9
4 6
2 3
1 5
7 8
2 9
5 6
2 6
7 9
20 36 34 28 23 29 23 19 31