Paths

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

문제

Orange the Cat found a tree (an undirected connected acyclic graph) with NN vertices numbered from 11 to NN. On each edge ii (1i<N1 ≤ i < N) connecting vertices x_ix\_i and y_iy\_i there are c_ic\_i special cat treats.

Orange can choose exactly KK vertices, walk from the root of the tree to each of the chosen vertices along the paths from the root to the respective vertices and take all the cat treats along those paths. Of course, he can only take the treats on each edge once. Because Orange is a curious cat, he wants to know the maximum possible number of treats he could take by choosing the KK vertices optimally, if the root of the tree were vertex ii, for each ii from 11 to NN.

입력

The first line of the input contains two integers NN and KK, the number of vertices of the tree and the number of vertices Orange will choose, respectively. The next N1N - 1 lines contain three integers each, x_ix\_i, y_iy\_i and c_ic\_i, describing the edges of the tree.

출력

On line ii for 1iN1 ≤ i ≤ N output the maximum number of treats Orange could take if the root of the tree were vertex ii.

제한

  • 1KN100,0001 ≤ K ≤ N ≤ 100\\,000
  • 0c_i1,000,000,0000 ≤ c\_i ≤ 1\\,000\\,000\\,000, for 1i<N1 ≤ i < N

힌트

If the root is vertex 11, then Orange can choose vertices 44, 66 and 99. The paths from the root to the chosen vertices are 12341 − 2 − 3 − 4, 1261 − 2 − 6, 1791 − 7 − 9 and the number of treats along those paths is 5+3+4+5+6+5=285 + 3 + 4 + 5 + 6 + 5 = 28. Note that the treats on edge 121 − 2 are only counted once.