시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB71332843.750%

문제

There are N cities in JOI Country, numbered from 1 through N. The cities are connected by N − 1 roads. The i-th road (1 ≤ i ≤ N − 1) connects the cities Ai and Bi bidirectionally. From any city to any city, it is possible to travel using some roads.

JOI Country has some local specialities. Each kind of speciality is assigned an integer between 1 and M, inclusive (some integer may not correspond to any speciality in JOI Country). Each city produces one kind of speciality. The city j (1 ≤ j ≤ N) produces the speciality Cj. Multiple cities may produce the same kind of speciality.

We define the distance between two cities as the minimum number of roads needed to pass to travel from one to the other. For the city x (1 ≤ x ≤ N), we say the city y (1 ≤ y ≤ N, y ≠ x) is a unique city if for any city z (1 ≤ z ≤ N, z ≠ x, z ≠ y) the distance between the cities x and y is different from the distance between the cities x and z.

Mr. K, the Minister of Transport in JOI Country, wants to know for each j (1 ≤ j ≤ N), the number of kinds of specialities produced in the unique cities for the city j.

Write a program which, given the information of roads in JOI Country and the kind of specialities produced in each city, calculates for each city, the number of kinds of specialities produced in the unique cities for it.

입력

Read the following data from the standard input.

N M
A1 B1
.
.
.
AN−1 BN−1
C1 · · · CN

출력

Write N lines to the standard output. The j-th line (1 ≤ j ≤ N) should contain the number of kinds of specialities produced in the unique cities for the city j.

제한

  • 2 ≤ N ≤ 200 000.
  • 1 ≤ M ≤ N.
  • 1 ≤ Ai ≤ N (1 ≤ i ≤ N − 1), 1 ≤ Bi ≤ N (1 ≤ i ≤ N − 1).
  • Ai ≠ Bi (1 ≤ i ≤ N − 1).
  • From any city to any city, it is possible to travel using some roads.
  • 1 ≤ Cj ≤ M (1 ≤ j ≤ N).

서브태스크

번호배점제한
14

N ≤ 2 000.

232

M = 1.

332

M = N, Cj = j (1 ≤ j ≤ N).

432

No additional constraints.

예제 입력 1

5 4
1 2
2 3
3 4
3 5
1 2 1 2 4

예제 출력 1

2
0
1
1
1

The unique cities for the city 1 are the cities 2 and 3, in which the specialities 2 and 1 are produced, so the answer is 2.

There are no unique cities for the city 2, so the answer is 0.

The unique city for the city is the city 1, in which the speciality 1 is produced, so the answer is 1.

The unique cities for the city 4 are the cities 1 and 3, in both of which the speciality 1 is produced, so the answer is 1.

The unique cities for the city 5 are the cities 1 and 3, in both of which the speciality 1 is produced, so the answer is 1.

Note that there does not exist a speciality 3.

예제 입력 2

7 1
1 2
2 3
3 4
4 5
5 6
6 7
1 1 1 1 1 1 1

예제 출력 2

1
1
1
0
1
1
1

예제 입력 3

10 10
2 6
5 8
10 8
1 4
10 6
4 5
10 7
6 9
3 7
1 2 3 4 5 6 7 8 9 10

예제 출력 3

4
3
4
2
0
2
2
0
3
2

예제 입력 4

22 12
9 6
12 13
4 20
21 22
3 19
2 9
6 18
18 11
18 3
16 2
6 4
3 17
16 10
8 16
22 1
16 14
15 8
9 21
2 12
21 5
12 7
1 1 4 8 4 11 7 6 7 11 6 11 10 4 7 5 3 12 9 6 12 2

예제 출력 4

2
0
1
1
1
1
1
0
0
1
2
0
1
1
2
0
2
1
2
3
0
0

채점 및 기타 정보

  • 예제는 채점하지 않는다.