import itertools

from scipy.sparse.csgraph import floyd_warshall



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

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

l=[list(map(int,input().split())) for i in range(m)]



d=[[float('inf')]*n for i in range(n)]

for i in range(n):

    d[i][i]=0

for i in l:

    d[i[0]-1][i[1]-1]=i[2]

    d[i[1]-1][i[0]-1]=i[2]

d=floyd_warshall(d)



ans=10**9

for i in itertools.permutations(r_l):

    t_ans=0

    for j in range(len(i)-1):

        t_ans+=d[i[j]-1][i[j+1]-1]

    ans=min(ans,t_ans)

print((int(ans)))
from scipy.sparse.csgraph import floyd_warshall

from itertools import permutations

from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))



n,m,r=nii()

r=list(nii())



s=[[float('inf')]*n for i in range(n)]

for i in range(n):

  for j in range(n):

    s[i][j]=0

for i in range(m):

  a,b,c=nii()

  a-=1

  b-=1

  s[a][b]=c

  s[b][a]=c



ws=floyd_warshall(s)



ans=10**9

for i in permutations(r):

  t_ans=0

  for j in range(1,len(i)):

    t_ans+=ws[i[j-1]-1][i[j]-1]

  ans=min(ans,t_ans)

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

n, m, r = list(map(int, input().split()))
r_l = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
d = [[float("inf")] * n for i in range(n)]
for i in range(n):
    d[i][i] = 0
for i in l:
    d[i[0] - 1][i[1] - 1] = i[2]
    d[i[1] - 1][i[0] - 1] = i[2]
d = floyd_warshall(d)
ans = 10**9
for i in itertools.permutations(r_l):
    t_ans = 0
    for j in range(len(i) - 1):
        t_ans += d[i[j] - 1][i[j + 1] - 1]
    ans = min(ans, t_ans)
print((int(ans)))

from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations
from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
n, m, r = nii()
r = list(nii())
s = [[float("inf")] * n for i in range(n)]
for i in range(n):
    for j in range(n):
        s[i][j] = 0
for i in range(m):
    a, b, c = nii()
    a -= 1
    b -= 1
    s[a][b] = c
    s[b][a] = c
ws = floyd_warshall(s)
ans = 10**9
for i in permutations(r):
    t_ans = 0
    for j in range(1, len(i)):
        t_ans += ws[i[j - 1] - 1][i[j] - 1]
    ans = min(ans, t_ans)
print((int(ans)))

-import itertools +from itertools import permutations +from sys import stdin -n, m, r = list(map(int, input().split())) -r_l = list(map(int, input().split())) -l = [list(map(int, input().split())) for i in range(m)] -d = [[float("inf")] * n for i in range(n)] +nii = lambda: list(map(int, stdin.readline().split())) +n, m, r = nii() +r = list(nii()) +s = [[float("inf")] * n for i in range(n)] -    d[i][i] = 0 -for i in l: -    d[i[0] - 1][i[1] - 1] = i[2] -    d[i[1] - 1][i[0] - 1] = i[2] -d = floyd_warshall(d) +    for j in range(n): +        s[i][j] = 0 +for i in range(m): +    a, b, c = nii() +    a -= 1 +    b -= 1 +    s[a][b] = c +    s[b][a] = c +ws = floyd_warshall(s) -for i in itertools.permutations(r_l): +for i in permutations(r): -    for j in range(len(i) - 1): -        t_ans += d[i[j] - 1][i[j + 1] - 1] +    for j in range(1, len(i)): +        t_ans += ws[i[j - 1] - 1][i[j] - 1]