#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 nodes, labeled from to , and the root is always labeled .
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.

Input Format
The first line contains two integers and , where is the number of nodes in the tree, and is the number of branches to retain.
The next 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 of the data, , and the number of apples on each branch does not exceed .