Orange the Cat found a tree (an undirected connected acyclic graph) with vertices numbered from to . On each edge connecting vertices and there are special cat treats.
Task
Orange can choose exactly vertices, walk from the root of the tree to each of the chosen vertices along the paths from the root to the respective vertices and take all the cat treats along those paths. Of course, he can only take the treats on each edge once. Because Orange is a curious cat, he wants to know the maximum possible number of treats he could take by choosing the vertices optimally, if the root of the tree were vertex , for each from to .
Input
The first line of the input contains two integers and , the number of vertices of the tree and the number of vertices Orange will choose, respectively. The next lines contain three integers each, and , describing the edges of the tree.
Output
On line for output the maximum number of treats Orange could take if the root of the tree were vertex .
Restrictions
- , for
# | Points | Restrictions |
---|---|---|
1 | 8 | |
2 | 11 | |
3 | 17 | |
4 | 20 | |
5 | 12 | |
6 | 32 | No further restrictions. |
Example
stdin
11 3
1 2 5
2 3 3
2 6 5
3 4 4
3 5 2
1 7 6
7 8 4
7 9 5
1 10 1
10 11 1
stdout
28
28
28
32
30
32
28
32
32
29
30
Explanation
If the root is vertex , then Orange can choose vertices and . The paths from the root to the chosen vertices are and the number of treats along those paths is . Note that the treats on edge are only counted once.