#P6118. [JOI 2019 Final] 独特的城市 / Unique Cities
[JOI 2019 Final] 独特的城市 / Unique Cities
Description
JOI Country has cities, numbered from to . These cities are connected by bidirectional roads. The -th road connects cities and . From any city, you can reach all cities.
JOI Country has some local products. Each product type is numbered between and (including and ), but some integers from to may not correspond to any product in JOI Country. Each city in JOI Country produces exactly one product. The product produced by city is . Multiple cities may produce the same product.
We define the distance between two cities as the minimum number of roads that must be passed through to go from one city to the other. For a city , we define a city () to be a unique city if and only if, for any city (), the distance between and is not equal to the distance between and .
Mr. K, the Minister of Transportation of JOI Country, wants to know how many different kinds of products can be produced in total by the unique cities of city .
Given the road information of JOI Country and the product produced by each city, write a program to compute, for each city, how many different kinds of products can be produced in total by its unique cities.
Input Format
The first line contains two integers , as described in the statement.
The next lines each contain two integers , as described in the statement.
The last line contains positive integers. The -th integer is , as described in the statement.
Output Format
Output lines. The -th line should contain the number of different kinds of products that can be produced in total by the unique cities of city .
5 4
1 2
2 3
3 4
3 5
1 2 1 2 4
2
0
1
1
1
7 1
1 2
2 3
3 4
4 5
5 6
6 7
1 1 1 1 1 1 1
1
1
1
0
1
1
1
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
4
3
4
2
0
2
2
0
3
2
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
2
0
1
1
1
1
1
0
0
1
2
0
1
1
2
0
2
1
2
3
0
0
Hint
Sample Explanation 1:
For city , its unique cities are cities and . City produces product , and city produces product , so there are kinds of products in total. Therefore the answer is .
For city , there are no unique cities, so output .
For city , its unique city is city . City produces product , so the answer is .
For city , its unique cities are cities and . Both cities and produce product , so the answer is .
For city , its unique cities are cities and . Both cities and produce product , so the answer is .
Note: No city produces product .
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, $1 \le N \le 2 \times 10^5, 1 \le M, A_i, B_i \le N, A_i \neq B_i, 1 \le C_j \le M$.
Translated by ChatGPT 5
京公网安备 11011102002149号