Unique Cities

각 도시에 특산품 종류가 배정된 트리에서, 모든 도시에 대해 그 도시로부터의 거리가 유일한 도시들이 가진 특산품 종류의 수를 구한다.

어려움9트리DFS수학조합론아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

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).