#Q155. 「一本通 5.2 例 1」二叉苹果树

「一本通 5.2 例 1」二叉苹果树

Description

There is a binary apple tree where every node that branches must have exactly two children, meaning no node has only one child. The tree has a total of NN nodes, labeled from 11 to NN, and the root is always labeled 11.

Each branch is described by the pair of node numbers it connects. Given that the tree has too many branches, some need to be pruned. However, some branches bear apples. Given the number of branches to retain, determine the maximum number of apples that can be preserved.

tree.png

Input Format

The first line contains two integers NN and QQ, where NN is the number of nodes in the tree, and QQ is the number of branches to retain.

The next N1N-1 lines describe the branches. Each line contains three integers: the first two are the node numbers connected by the branch, and the third is the number of apples on that branch.

Output Format

Output a single line with the maximum number of apples that can be preserved.

Sample 1

5 2
1 3 1
1 4 10
2 3 20
3 5 20

21

Constraints & Hints

For 100%100\% of the data, 1QN100,N11\le Q \le N \le 100, N\neq 1, and the number of apples on each branch does not exceed 3000030000.