#P6058. [加油武汉] 体温调查
[加油武汉] 体温调查
Description
Given a tree whose root node is numbered . A medical worker starts from the root, moves along the edges, collects information from every leaf, and finally returns to the root. The visiting order is fixed: whenever he reaches a node , he first goes to the child with the smallest index, visits all households in that child subtree and comes back to , then goes to the child with the second smallest index, and so on, until all households in the subtree of have been visited and he returns to the parent. It can be seen that the order of visiting leaves is exactly the order in the household address list.
Moving along an edge takes time. To save time, we may split the household list into continuous segments, and let medical workers start from the root at the same time. Each worker visits the households in one segment and then returns. Please compute the minimum time needed to finish collecting temperatures for all households.
Input Format
The first line contains two integers , representing the number of nodes in the tree and the number of medical workers.
The next lines each contain three integers , representing an edge between and , with travel time cost .
Output Format
Output one integer in one line, representing the minimum time needed to finish the temperature survey for all households.
11 2
1 2 2
1 3 3
2 4 1
3 5 2
4 6 2
4 7 3
5 8 1
6 9 3
6 10 25
8 11 4
66
Hint
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , , , , where is the number of leaves.
Sample Explanation
See the figure in the Background.
The first person’s route is RT->Z1->Z2->RT, costing 66.
The second person’s route is RT->Z3->Z4->RT, costing 32.
The plan where one person visits Z2 and the other visits Z1, Z3, Z4 is invalid.
Translated by ChatGPT 5
京公网安备 11011102002149号