#P2935. [USACO09JAN] Best Spot S
[USACO09JAN] Best Spot S
Description
John owns pastures.
Bessie especially likes of them.
All pastures are connected by bidirectional roads. The -th road connects pastures , and takes units of time to traverse.
As a cow who always wants to improve her lifestyle, Bessie hopes that one day she will wake up at a pasture where the average time to reach all pastures she likes is minimized. At which pasture should she sleep the day before? Please help Bessie find this best pasture.
For example, consider the pasture layout shown below, where starred pastures are the most favored ones, and the numbers in brackets are the traversal times of the cow paths.
1*--[4]--2--[2]--3
| |
[3] [4]
| |
4--[3]--5--[1]---6---[6]---7--[7]--8*
| | | |
[3] [2] [1] [3]
| | | |
13* 9--[3]--10*--[1]--11*--[3]--12*
下表显示了牧场 和 与贝茜最喜欢的牧场的各个距离、平均距离和最终求出的最佳牧场:
* * * * * * 最喜欢的牧场 * * * * * *
可能的 牧场 牧场 牧场 牧场 牧场 牧场 平均
最佳牧场 1 8 10 11 12 13 距离
------------ -- -- -- -- -- -- -----------
4 7 16 5 6 9 3 46/6 = 7.67
5 10 13 2 3 6 6 40/6 = 6.67
6 11 12 1 2 5 7 38/6 = 6.33
7 16 7 4 3 6 12 48/6 = 8.00
9 12 14 3 4 7 8 48/6 = 8.00
10 12 11 0 1 4 8 36/6 = 6.00 ** 最佳的
11 13 10 1 0 3 9 36/6 = 6.00
12 16 13 4 3 0 12 48/6 = 8.00
From the table, in the sample setting, pasture has the smallest average distance to all pastures Bessie likes, making it the best pasture.
Input Format
The first line contains three integers ,,.
The next lines each contain a single integer, the index of a pasture that Bessie likes.
The next lines each contain three integers ,,, indicating there is a bidirectional path between and with traversal time .
Output Format
Output a single integer, the index of the best pasture. If there are multiple best pastures, output the smallest index.
13 6 15
11
13
10
12
8
1
2 4 3
7 11 3
10 11 1
4 13 3
9 10 3
2 3 2
3 5 4
5 9 2
6 7 6
5 6 1
1 2 4
4 5 3
11 12 3
6 10 1
7 8 7
10
Hint
Translated by AASDFGHJKL (1035916).
Translated by ChatGPT 5
京公网安备 11011102002149号