Under construction

Still being built. Things may change

Unique Cities

Time limit2sMemory limit512 MB

Summary
For each city, count the distinct specialties among the unique cities, those whose distance from it differs from every other city's distance to it.
Level

Hard9 of 10

Topics
Tree, Divide and conquer, DFS
Solved
No attempts yet

Problem

JOI Country has NN cities, numbered from 11 through NN. The cities are connected by N−1N-1 roads. The ii-th road (1≤i≤N−11 \le i \le N-1) connects cities AiA_i and BiB_i in both directions. From any city to any other city, you can travel using some roads.

JOI Country has some local specialties. Each kind of specialty is assigned an integer from 11 to MM, inclusive. Some integers may not correspond to any specialty in JOI Country. Each city produces one kind of specialty. City jj (1≤j≤N1 \le j \le N) produces specialty CjC_j. Multiple cities may produce the same kind of specialty.

The distance between two cities is the minimum number of roads needed to travel from one to the other. For city xx (1≤x≤N1 \le x \le N), city yy (1≤y≤N1 \le y \le N, y≠xy \ne x) is a unique city if, for every city zz (1≤z≤N1 \le z \le N, z≠xz \ne x, z≠yz \ne y), the distance between xx and yy differs from the distance between xx and zz.

Mr. K, the Minister of Transport in JOI Country, wants to know, for each jj (1≤j≤N1 \le j \le N), the number of kinds of specialties produced in the unique cities for city jj. Write a program that calculates this value for every city.

Input

The first line contains NN and MM. Each of the next N−1N-1 lines contains AiA_i and BiB_i. The last line contains NN integers C1⋯CNC_1 \cdots C_N, separated by spaces.

Output

Print NN lines. The jj-th line contains the number of kinds of specialties produced in the unique cities for city jj.

Constraints

  • 2≤N≤2000002 \le N \le 200000
  • 1≤M≤N1 \le M \le N
  • 1≤Ai≤N1 \le A_i \le N (1≤i≤N−11 \le i \le N-1), 1≤Bi≤N1 \le B_i \le N (1≤i≤N−11 \le i \le N-1)
  • Ai≠BiA_i \ne B_i (1≤i≤N−11 \le i \le N-1)
  • From any city to any other city, you can travel using some roads.
  • 1≤Cj≤M1 \le C_j \le M (1≤j≤N1 \le j \le N)

Examples4

  1. Example 1

    Input
    5 4
    1 2
    2 3
    3 4
    3 5
    1 2 1 2 4
    
    Expected output
    2
    0
    1
    1
    1
    
  2. Example 2

    Input
    7 1
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    1 1 1 1 1 1 1
    
    Expected output
    1
    1
    1
    0
    1
    1
    1
    
  3. Example 3

    Input
    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
    
    Expected output
    4
    3
    4
    2
    0
    2
    2
    0
    3
    2
    
  4. Example 4

    Input
    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
    
    Expected output
    2
    0
    1
    1
    1
    1
    1
    0
    0
    1
    2
    0
    1
    1
    2
    0
    2
    1
    2
    3
    0
    0