#P2935. [USACO09JAN] Best Spot S

[USACO09JAN] Best Spot S

Description

John owns P(1P500)P(1 \leq P \leq 500) pastures.

Bessie especially likes F(1FP)F(1\leq F \leq P) of them.

All pastures are connected by C(1<C8000)C(1 < C \leq 8000) bidirectional roads. The ii-th road connects pastures aia_i,bib_i (1aiP,1biP)(1 \leq a_i \leq P,1 \leq b_i \leq P) and takes Ti(1Ti<892)T_i(1 \leq T_i < 892) 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 FF 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*

下表显示了牧场 4,5,6,7,9,10,114,5,6,7,9,10,111212 与贝茜最喜欢的牧场的各个距离、平均距离和最终求出的最佳牧场:

                    * * * * * * 最喜欢的牧场 * * * * * *
  可能的         牧场    牧场    牧场    牧场    牧场    牧场         平均
 最佳牧场          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 1010 has the smallest average distance to all pastures Bessie likes, making it the best pasture.

Input Format

The first line contains three integers PP,FF,CC.

The next FF lines each contain a single integer, the index of a pasture that Bessie likes.

The next CC lines each contain three integers aia_i,bib_i,TiT_i, indicating there is a bidirectional path between aia_i and bib_i with traversal time TiT_i.

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