from itertools import permutations

from scipy.sparse.csgraph import floyd_warshall

n,m,r=list(map(int,input().split()))

vis=list(map(int,input().split()))

INF=10**18

path=[[INF]*n for i in range(n)]

for i in range(m):

  a,b,c=list(map(int,input().split()))

  path[a-1][b-1]=c

  path[b-1][a-1]=c

path=floyd_warshall(path)

ans=10**18

for root in permutations(vis):

  cnt=0

  for j in range(1,r):

    cnt+=path[root[j-1]-1][root[j]-1]

  ans=min(ans,cnt)

print((int(ans)))
import itertools

n,m,r=list(map(int,input().split()))

point=list(map(int,input().split()))

g=[[10**9]*n for i in range(n)]

for _ in range(m):

  u,v,c=list(map(int,input().split()))

  g[u-1][v-1]=g[v-1][u-1]=c

for k in range(n):

  for i in range(n):

    for j in range(n):

      g[i][j]=min(g[i][j],g[i][k]+g[k][j])

for i in range(n):

  g[i][i]=0

ans=10**18

for v in itertools.permutations(point):

  tmp=0

  for i in range(r-1):

    tmp+=g[v[i]-1][v[i+1]-1]

  ans=min(ans,tmp)

print(ans)
from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall

n, m, r = list(map(int, input().split()))
vis = list(map(int, input().split()))
INF = 10**18
path = [[INF] * n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    path[a - 1][b - 1] = c
    path[b - 1][a - 1] = c
path = floyd_warshall(path)
ans = 10**18
for root in permutations(vis):
    cnt = 0
    for j in range(1, r):
        cnt += path[root[j - 1] - 1][root[j] - 1]
    ans = min(ans, cnt)
print((int(ans)))

import itertools

n, m, r = list(map(int, input().split()))
point = list(map(int, input().split()))
g = [[10**9] * n for i in range(n)]
for _ in range(m):
    u, v, c = list(map(int, input().split()))
    g[u - 1][v - 1] = g[v - 1][u - 1] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j])
for i in range(n):
    g[i][i] = 0
ans = 10**18
for v in itertools.permutations(point):
    tmp = 0
    for i in range(r - 1):
        tmp += g[v[i] - 1][v[i + 1] - 1]
    ans = min(ans, tmp)
print(ans)

-from itertools import permutations -from scipy.sparse.csgraph import floyd_warshall +import itertools -vis = list(map(int, input().split())) -INF = 10**18 -path = [[INF] * n for i in range(n)] -for i in range(m): -    a, b, c = list(map(int, input().split())) -    path[a - 1][b - 1] = c -    path[b - 1][a - 1] = c -path = floyd_warshall(path) +point = list(map(int, input().split())) +g = [[10**9] * n for i in range(n)] +for _ in range(m): +    u, v, c = list(map(int, input().split())) +    g[u - 1][v - 1] = g[v - 1][u - 1] = c +for k in range(n): +    for i in range(n): +        for j in range(n): +            g[i][j] = min(g[i][j], g[i][k] + g[k][j]) +for i in range(n): +    g[i][i] = 0 -for root in permutations(vis): -    cnt = 0 -    for j in range(1, r): -        cnt += path[root[j - 1] - 1][root[j] - 1] -    ans = min(ans, cnt) -print((int(ans))) +for v in itertools.permutations(point): +    tmp = 0 +    for i in range(r - 1): +        tmp += g[v[i] - 1][v[i + 1] - 1] +    ans = min(ans, tmp) +print(ans)