Under construction

Still being built. Things may change

One Path

Time limit1sMemory limit1024 MB

Summary
For each i from 0 to K, find the largest graph weight reachable after moving i tree edges, each reattached with its original weight.
Level

Hard8 of 10

Topics
Tree, Dynamic programming
Solved
No attempts yet

Problem

You are given a tree TT with NN vertices. Each edge has a positive integer weight.

You can perform the following operation on the tree.

  • Delete an edge from the graph, then add a new edge between any two distinct vertices. The new edge must have the same weight as the deleted edge. The resulting graph does not need to be a tree.

The weight of a path is the sum of the weights of the edges on the path. The distance between two vertices uu and vv is the weight of the shortest path from uu to vv, that is, the path with the minimum weight. If there is no such path, the distance is 00.

The weight of a graph is the maximum distance between any two vertices.

Find the largest weight of the graph that can be obtained by performing the operation exactly ii times, for i=0,1,…,Ki=0,1,\dots,K.

Input

The first line contains two space-separated integers NN and KK. The ii-th of the following N−1N-1 lines contains three space-separated integers uiu_i, viv_i, and wiw_i, which describe an undirected edge with weight wiw_i that connects two different vertices uiu_i and viv_i. It is guaranteed that the edges form a tree.

Output

Output K+1K+1 space-separated integers. The ii-th integer is the largest weight of the graph that can be obtained by performing the operation exactly i−1i-1 times.

Constraints

  • 2≤N≤2 0002\le N\le 2\,000
  • 0≤K≤2 0000\le K\le 2\,000
  • 1≤ui<vi≤N1\le u_i<v_i\le N (1≤i≤N−11\le i\le N-1)
  • 1≤wi≤1091\le w_i\le 10^9 (1≤i≤N−11\le i\le N-1)

Examples2

  1. Example 1

    Input
    5 1
    1 3 2
    4 5 4
    3 4 3
    2 3 7
    
    Expected output
    14 16
    
  2. Example 2

    Input
    7 2
    1 2 4
    2 3 6
    2 4 2
    4 5 5
    2 6 1
    4 7 3
    
    Expected output
    13 20 21