#P3047. [USACO12FEB] Nearby Cows G

[USACO12FEB] Nearby Cows G

Description

Farmer John has noticed that his cows often move between nearby fields. Taking this into account, he wants to plant enough grass in each of his fields not only for the cows situated initially in that field, but also for cows visiting from nearby fields.

Specifically, FJ's farm consists of NN fields (1N100,000)(1 \leq N \leq 100,000), where some pairs of fields are connected with bi-directional trails (N1N-1 of them in total). FJ has designed the farm so that between any two fields ii and jj, there is a unique path made up of trails connecting between ii and jj. Field ii is home to CiC_i cows, although cows sometimes move to a different field by crossing up to KK trails (1K20)(1 \leq K \leq 20).

FJ wants to plant enough grass in each field ii to feed the maximum number of cows MiM_i that could possibly end up in that field -- that is, the number of cows that can potentially reach field ii by following at most KK trails. Given the structure of FJ's farm and the value of CiC_i for each field ii, please help FJ compute MiM_i for every field ii.

Input Format

  • Line 11: Two space-separated integers, NN and KK.

  • Lines 22 to NN: Each line contains two space-separated integers, ii and jj (1i,jN)(1 \leq i,j \leq N) indicating that fields ii and jj are directly connected by a trail.

  • Lines N+1N+1 to 2N2N: Line N+iN+i contains the integer CiC_i. (0Ci1000)(0 \leq C_i \leq 1000)

Output Format

  • Lines 11 to NN: Line ii should contain the value of MiM_i.
6 2 
5 1 
3 6 
2 4 
2 1 
3 2 
1 
2 
3 
4 
5 
6 

15 
21 
16 
10 
8 
11 

Hint

There are 66 fields, with trails connecting (5,1)(5,1), (3,6)(3,6), (2,4)(2,4), (2,1)(2,1), and (3,2)(3,2). Field ii has Ci=iC_i = i cows.

Field 11 has M1=15M_1 = 15 cows within a distance of 22 trails, etc.