Regular Meeting 2
Time limit3sMemory limit1024 MB
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 vertices is given. The vertices are numbered from 1 to . The -th edge connects vertex and vertex , and its weight is .
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 meetings. The -th meeting is attended by people living at vertices numbered from 1 to . Because of the coronavirus situation this year, each meeting is held in person at places and continued online. Each meeting uses distinct vertices of the tree. The vertices are chosen independently for each meeting. Once the vertices are chosen, each person travels to the one of that requires the smallest travel distance.
The value of is one of the values from 1 to . For each meeting, compute the sum, over to , 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 and the integer , separated by a space.
From the second line onward, the lines describe the edges. Line contains three integers , , and , separated by spaces. This means there is an edge with weight connecting vertex and vertex .
Output
Print lines. The -th line contains the answer for the -th meeting.