In 2010, the "Moțoc" kindergarten held an unusual chalk drawing contest in Iași. Each participant had to create a beautiful drawing, but was allowed to lift the chalk off the ground and resume drawing elsewhere only a limited number of times.
Sixteen years later, inspired by that contest, one of the children who took part in it came up with the following problem idea:
A tree is a connected undirected graph without cycles, having vertices and exactly edges. A weighted tree, with vertices labeled from to , needs to be drawn.
The weight of each edge , which is a value , represents the exact amount of chalk consumed to trace the edge .
A drawing of the tree is a way to traverse the tree with a piece of chalk such that every edge is traversed at least once. During the drawing, we are allowed to:
- retrace edges, meaning that we can traverse them multiple times; each time we traverse an edge, we consume the same amount of chalk;
- lift the chalk at most times, relocating it, after each lift, from its current vertex to any other vertex in the tree (lifting and relocating the chalk is instantaneous and costs nothing).
Note: Placing the chalk on the tree for the very first time at the beginning of the drawing does not count as a lift.
The cost of a drawing is the total amount of chalk used, which is calculated as , where is the set of edges and is the number of times edge is traversed during the entire drawing process.
Task
Given a weighted tree with vertices and an integer , determine the minimum cost of a drawing of the tree that uses at most chalk lifts.
Input data
The first line of the input contains two space-separated integers and , representing the number of vertices and the maximum number of chalk lifts allowed.
The following lines contain three space-separated integers , , and , meaning there is an undirected edge of weight connecting vertices and .
Output data
The first line of the output must contain a single integer, representing the minimum cost of the drawing.
Constraints and clarifications
- for any edge
- The given graph is guaranteed to be a valid tree.
| # | Score | Constraints |
|---|---|---|
| 0 | 0 | Examples |
| 1 | 6 | and for every edge. |
| 2 | 7 | . |
| 3 | 3 | The degree of every node is at most . |
| 4 | 8 | All edges have one endpoint in vertex . |
| 5 | 11 | . |
| 6 | 10 | . |
| 7 | 12 | Every simple path has at most edges. |
| 8 | 20 | . |
| 9 | 23 | No further restrictions. |
Example 1
stdin
7 0
1 2 5
2 3 5
1 4 5
4 5 5
1 6 5
6 7 5
stdout
40
Explanation

With , the drawing must be a single continuous traversal of the tree.
A valid optimal drawing is: .
There are 2 retraced edges: ([,] and [,]).
Example 2
stdin
7 1
1 2 5
2 3 5
1 4 5
4 5 5
1 6 5
6 7 5
stdout
30
Explanation

With , one pen lift is allowed.
An optimal choice is tracing: , followed by lifting the chalk and relocating it to vertex , then tracing .