#P2916. [USACO08NOV] Cheering up the Cow G
[USACO08NOV] Cheering up the Cow G
Description
Farmer John has pastures (numbered to , ), each inhabited by one cow. These pastures are connected by bidirectional paths (). Each path connects pastures and (; ; ), and traversing it takes units of time (). There is at most one direct path between any pair of pastures.
John plans to remove as many roads as possible while keeping all pastures connected. He knows the cows will be very sad after the demolition, so he plans to comfort them afterward. John may choose any pasture to start his comforting tour. After he has visited all cows, he must return to his starting pasture. Each time he passes pasture , he must spend () units of time to talk with the cow there; even if he has already talked before, he must stop and talk again. Note that both when setting out and when returning, he must talk to the cow at the starting pasture.
Assume Farmer John follows your recommendation on which paths to keep, and you also choose the optimal lodging pasture. Compute the minimal total time required while ensuring that each cow is visited at least once.
Input Format
- Line : Two space-separated integers: and .
- Lines to : Line contains one integer: .
- Lines to : Line contains three space-separated integers: , , and .
Output Format
- Line : A single integer, the minimal total time needed to visit all cows (including the two chats at the lodging pasture).
5 7
10
10
20
6
30
1 2 5
2 3 5
2 4 12
3 4 17
2 5 15
3 5 6
4 5 12
176
Hint
+-(15)-+
/ \
/ \
1-(5)-2-(5)-3-(6)--5
\ /(17) /
(12)\ / /(12)
4------+
Keep these paths:
1-(5)-2-(5)-3 5
\ /
(12)\ /(12)
*4------+
Choose pasture as the lodging pasture, visit in the order , and finally return to sleep. The total time is units.
Translated by ChatGPT 5
京公网安备 11011102002149号