# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1211878 | ackerman2840 | Crocodile's Underground City (IOI11_crocodile) | C11 | 0 ms | 0 KiB |
from heapq import heappop,heappush
n,m,k=map(int,input().split())
adj=[[] for _ in range(n)]
for _ in range(m):
u,v,d=map(int,input().split())
adj[u].append((v,d))
adj[v].append((u,d))
exit=list(map(int,input().split()))
dist=[]
for _ in range(n):
dist.append([float('inf'),float('inf')])
pq=[]
for i in exit:
dist[i]=[0,0]
heappush(pq,(0,i))
while pq:
d,node=heappop(pq)
d*=-1
if dist[node][1]!=d:continue
for to,dd in adj[node]:
if dist[to][0]>d+dd:
if dist[to][0]<dist[to][1]:heappush(pq,(-dist[to][0],to))
dist[to][1]=dist[to][0]
dist[to][0]=d+dd
elif dist[to][1]>d+dd:
heappush(pq,(-d-dd,to))
dist[to][1]=d+dd
print(dist[0][1])