Under construction

Still being built. Things may change

Regular Meeting 2

Time limit3sMemory limit1024 MB

Summary
For each prefix of vertices 1 to i in a weighted tree, find the sum over X = 1 to K of the minimum possible maximum minimax-distance when placing X centers.
Level

Hard9 of 10

Topics
Tree, Greedy, Dynamic programming
Solved
No attempts yet

Problem

A tree with NN vertices is given. The vertices are numbered from 1 to NN. The ii-th edge connects vertex AiA_i and vertex BiB_i, and its weight is CiC_i. (1≤i<N)(1 \leq i < N)

The distance between two vertices is the maximum weight among the edges on the shortest path connecting them. The distance between a vertex and itself is 0.

People living in the tree hold NN meetings. The ii-th meeting is attended by people living at vertices numbered from 1 to ii. Because of the coronavirus situation this year, each meeting is held in person at XX places and continued online. Each meeting uses XX distinct vertices v1,⋯ ,vXv_1, \cdots, v_X of the tree. The vertices are chosen independently for each meeting. Once the vertices are chosen, each person travels to the one of v1,⋯ ,vXv_1, \cdots, v_X that requires the smallest travel distance.

The value of XX is one of the values from 1 to KK. For each meeting, compute the sum, over X=1X = 1 to KK, of the minimum possible value of the maximum travel distance of the people, where the minimum is taken over the choice of vertices.

Input

The first line contains the number of vertices NN and the integer KK, separated by a space. (1≤K≤N≤300 000)(1 \leq K \leq N \leq 300\,000)

From the second line onward, the N−1N-1 lines describe the edges. Line i+1i+1 contains three integers AiA_i, BiB_i, and CiC_i, separated by spaces. This means there is an edge with weight CiC_i connecting vertex AiA_i and vertex BiB_i. (1≤i<N)(1 \leq i < N) (1≤Ai,Bi,Ci≤N)(1 \leq A_i, B_i, C_i \leq N)

Output

Print NN lines. The ii-th line contains the answer for the ii-th meeting. (1≤i≤N)(1 \leq i \leq N)

Examples2

  1. Example 1

    Input
    10 4
    5 1 2
    1 6 4
    6 2 1
    2 8 9
    8 3 5
    3 4 8
    4 10 9
    10 9 8
    9 7 7
    
    Expected output
    0
    4
    13
    21
    23
    23
    30
    31
    33
    34
    
  2. Example 2

    Input
    8 3
    7 3 4
    4 5 2
    3 6 1
    6 8 6
    8 5 1
    2 5 8
    1 5 2
    
    Expected output
    0
    8
    14
    16
    16
    16
    18
    18