#P7460. [2017年杭电多校]RXD and dividing
[2017年杭电多校]RXD and dividing
RXD and dividing
Problem Description
RXD has a tree , with the size of . Each edge has a cost. Define as the the cost of the minimal Steiner Tree of the set on tree . he wants to divide into parts , where and for all different , we can conclude that . Then he calulates . He wants to maximize the . might be empty. means that you need to choose a couple of edges on the tree to make all the points in connected, and you need to minimize the sum of the cost of these edges. is equal to the minimal cost
Input
There are several test cases, please keep reading until EOF. For each test case, the first line consists of 2 integer , which means the number of the tree nodes , and means the number of parts. The next lines consists of 2 integers, , means a tree edge with cost . It is guaranteed that the edges would form a tree. There are 4 big test cases and 50 small test cases. small test case means .
Output
For each test case, output an integer, which means the answer.
Sample Input
5 4
1 2 3
2 3 4
2 4 5
2 5 6
Sample Output
27
Source
2017 Multi-University Training Contest - Team 3