#Lutece0550. Nearby Cows

Nearby Cows

Migrated from Lutece 550 Nearby Cows

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

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,0001 \leq N \leq 100,000), where some pairs of fields are connected with bidirectional trails (N1N-1 of them in total). FJ has designed the farm so that between any two fields i and j, there is a unique path made up of trails connecting between ii and jj. Field ii is home to C(i)C(i) cows, although cows sometimes move to a different field by crossing up to KK trails (1K201 \leq K \leq 20).

FJ wants to plant enough grass in each field i to feed the maximum number of cows, M(i)M(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 C(i)C(i) for each field ii, please help FJ compute M(i)M(i) for every field ii.

Input

  • Line 11: Two space-separated integers, NN and KK.
  • Lines 2N2\cdots N: Each line contains two space-separated integers, ii and jj (1i,jN1 \leq i,j \leq N) indicating that fields ii and jj are directly connected by a trail.
  • Lines N+12NN+1\cdots 2N: Line N+iN+i contains the integer C(i)C(i). (0C(i)10000 \leq C(i) \leq 1000)

Output

  • Lines 1N1\cdots N: Line ii should contain the value of M(i)M(i).

Samples

6 2
5 1
3 6
2 4
2 1
3 2
1
2
3
4
5
6
15
21
16
10
8
11

Resources

USACO Feb 2012