Test instructions
There are n cities, m-strips without sides, of which K cities are warehouses
Now choose a bakery in a non-warehouse city, making it a minimum of one warehouse and a minimum for all warehouse distances
(1≤ n, m ≤10^5, 0≤ k ≤ n)
Analysis:
The data range determines the solution using only O (n) or O (n log n)
After thinking, you can find that the bakery must be selected in a city directly connected to a warehouse.
Otherwise, it will be through another indirectly connected to the city to go, a few more roads
1 varA,b,c,flag:Array[1..100000] ofLongint;2 N,m,k,i,ans,x:longint;3 4 begin5 readln (n,m,k);6 fori:=1 toM Doreadln (A[i],b[i],c[i]);7 fori:=1 toK Do8 begin9 read (x);Tenflag[x]:=1; One End; Aans:=Maxlongint; - fori:=1 toM Do - ifflag[a[i]]+flag[b[i]]=1 Then the ifC[i]<ans Thenans:=C[i]; - ifAns<maxlongint Thenwriteln (ANS) - ElseWriteln (-1); - End.
"cf707b" Bakery (idea title)