One Path
Time limit1sMemory limit1024 MB
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 with 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 and is the weight of the shortest path from to , that is, the path with the minimum weight. If there is no such path, the distance is .
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 times, for .
Input
The first line contains two space-separated integers and . The -th of the following lines contains three space-separated integers , , and , which describe an undirected edge with weight that connects two different vertices and . It is guaranteed that the edges form a tree.
Output
Output space-separated integers. The -th integer is the largest weight of the graph that can be obtained by performing the operation exactly times.
Constraints
- ()
- ()