Problem5324--ABC163——Task F:path pass i

5324: ABC163——Task F:path pass i

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

We have a tree with NN vertices numbered 11 to NN. The ii-th edge in this tree connects Vertex aiai and bibi. Additionally, each vertex is painted in a color, and the color of Vertex ii is cici. Here, the color of each vertex is represented by an integer between 11 and NN (inclusive). The same integer corresponds to the same color; different integers correspond to different colors.

For each k=1,2,...,Nk=1,2,...,N, solve the following problem:

  • Find the number of simple paths that visit a vertex painted in the color kk one or more times.

Note: The simple paths from Vertex uu to vv and from vv to uu are not distinguished.

Input

Input is given from Standard Input in the following format:
N
c1 c2 ... cN a1 b1 .
.
aN bN

Output

Print the answers for k=1,2,...,Nk=1,2,...,N in order, each in its own line. 

Sample 1 Input

3
1 2 1
1 2
2 3

Sample 1 Output

5
4
0

HINT

【样例 1 说明】

Let Pi,jPi,j denote the simple path connecting Vertex ii and jj.

There are 55 simple paths that visit a vertex painted in the color 11 one or more times:
P1,1,P1,1, P1,2,P1,2, P1,3,P1,3, P2,3,P2,3, P3,3P3,3

There are 44 simple paths that visit a vertex painted in the color 22 one or more times:
P1,2,P1,2, P1,3,P1,3, P2,2,P2,2, P2,3P2,3

There are no simple paths that visit a vertex painted in the color 33 one or more times.
【样例 2 输入】

1
1
【样例 2 输出】
1
【样例 3 输入】
2
1 2
1 2
【样例 3 输出】
2
2
【样例 4 输入】
5
1 2 3 4 5
1 2
2 3
3 4
3 5
【样例 4 输出】
5
8
10
5
5
【样例 5 输入】
8
2 7 2 5 4 1 7 5
3 1
1 2
2 7
4 5
5 6
6 8
7 8
【样例 5 输出】
18
15
0
14
23
0
23
0
【数据范围】
【题目出处】
AtCoder Beginner Contest 163,Task F。https://atcoder.jp/contests/abc163/tasks/abc163_f

Source/Category

AtCoder_ABC 100.163.ABC163