#abc220f. [abc220_f]Distance Sums 2

[abc220_f]Distance Sums 2

Problem Statement

Given is a tree with NN vertices. The vertices are numbered 1,2,ldots,N1,2,\\ldots ,N, and the ii-th edge is an undirected edge connecting Vertices uiu_i and viv_i.

For each integer i,(1leqileqN)i\\,(1 \\leq i \\leq N), find sumj=1Ndis(i,j)\\sum_{j=1}^{N}dis(i,j).

Here, dis(i,j)dis(i,j) denotes the minimum number of edges that must be traversed to go from Vertex ii to Vertex jj.

Constraints

  • 2leqNleq2times1052 \\leq N \\leq 2 \\times 10^5
  • 1lequi<vileqN1 \\leq u_i < v_i \\leq N
  • The given graph is a tree.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN u1u_1 v1v_1 u2u_2 v2v_2 vdots\\vdots uN1u_{N-1} vN1v_{N-1}

Output

Print NN lines.

The ii-th line should contain sumj=1Ndis(i,j)\\sum_{j=1}^{N}dis(i,j).


Sample Input 1

3
1 2
2 3

Sample Output 1

3
2
3

We have:

dis(1,1)+dis(1,2)+dis(1,3)=0+1+2=3dis(1,1)+dis(1,2)+dis(1,3)=0+1+2=3,

dis(2,1)+dis(2,2)+dis(2,3)=1+0+1=2dis(2,1)+dis(2,2)+dis(2,3)=1+0+1=2,

dis(3,1)+dis(3,2)+dis(3,3)=2+1+0=3dis(3,1)+dis(3,2)+dis(3,3)=2+1+0=3.


Sample Input 2

2
1 2

Sample Output 2

1
1

Sample Input 3

6
1 6
1 5
1 3
1 4
1 2

Sample Output 3

5
9
9
9
9
9