Flower's Land

아직 제출이 없습니다시간 제한8초메모리 제한2048 MB

문제

The Kingdom of Flowers consists of nn cities, and the ii-th city grows a_ia\_i flowers. There are n1n-1 roads, where the ii-th road connects cities u_iu\_i and v_iv\_i. It is guaranteed that for any two cities there is a path connecting them.

Now, the Kingdom of Flowers wants to hold a flower exhibition. To do that, you need to first choose a city zz to build an exhibition hall, and then select exactly kk cities x_1,x_2,,x_kx\_1, x\_2, \ldots, x\_k and transport the flowers from those kk cities to the city zz.

To avoid upsetting people in cities along the path, the organizers stipulated that if city xx was selected, then all cities on the path from xx to zz had to be selected as well. In particular, this means that city zz must be selected.

For each z=1,2,,nz = 1, 2, \ldots, n, find the maximum number of flowers that can be transported if city zz is chosen to build the exhibition hall.

입력

The first line of the input contains two integers nn and kk (1n40,0001 \le n \le 40\\,000, 1kmin(n,3000)1 \le k \le \min(n, 3000)).

The next line of the input contains nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n (1a_i51051 \le a\_i \le 5 \cdot 10^5).

Each of the next n1n-1 lines contains two integers xx and yy (1x,yn1 \le x, y \le n, xyx \ne y), indicating that there is an edge between vertices xx and yy. It is guaranteed that the given graph is a tree.

출력

Output a single line containing nn integers f_1,f_2,,f_nf\_1, f\_2, \ldots, f\_n, where f_if\_i denotes the answer for z=iz = i.