#P2986. [USACO10MAR] Great Cow Gathering G
[USACO10MAR] Great Cow Gathering G
Description
Bessie is planning the annual grand cow gathering, with cows coming from all over the country. Of course, she will choose the most convenient place to hold it.
Each cow lives on one of the farms, which are connected by roads so that any farm is reachable from any other. Road connects farms and with length . The gathering may be held at any of the farms. In addition, farm contains cows.
When choosing the location, Bessie wants to maximize convenience (that is, minimize inconvenience). If farm is chosen as the location, its inconvenience is the sum, over all other farms, of the distance each cow must travel to attend. For example, if the distance from farm to farm is , then the total distance contributed by farm is . Help Bessie find the most convenient farm for the gathering.
Input Format
- Line 1: an integer .
- Lines 2 to : line contains a single integer .
- Lines to : line contains integers , , and .
Output Format
A single line containing one integer, the minimum inconvenience.
5
1
1
0
0
2
1 3 1
2 3 2
3 4 3
4 5 3
15
Hint
Constraints
, , .
Translated by ChatGPT 5
京公网安备 11011102002149号