import itertools

from scipy.sparse.csgraph import floyd_warshall



N,M,R=list(map(int,input().split()))

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

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



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

for i in range(M):

    a,b,c=l[i]

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

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

for i in range(N):

    s[i][i]=0



s=floyd_warshall(s)

#print(s)

ans=10**9

for i in itertools.permutations(r):

#    print(i)

    temp_ans=0

    for j in range(R-1):

        temp_ans+=s[i[j]-1][i[j+1]-1]

    ans=min(ans,temp_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)))
import itertools
from scipy.sparse.csgraph import floyd_warshall

N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(M)]
s = [[float("inf") for i in range(N)] for i in range(N)]
for i in range(M):
    a, b, c = l[i]
    s[a - 1][b - 1] = c
    s[b - 1][a - 1] = c
for i in range(N):
    s[i][i] = 0
s = floyd_warshall(s)
# print(s)
ans = 10**9
for i in itertools.permutations(r):
    #    print(i)
    temp_ans = 0
    for j in range(R - 1):
        temp_ans += s[i[j] - 1][i[j + 1] - 1]
    ans = min(ans, temp_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)))

-N, M, R = list(map(int, input().split())) -r = list(map(int, input().split())) -l = [list(map(int, input().split())) for i in range(M)] -s = [[float("inf") for i in range(N)] for i in range(N)] -for i in range(M): -    a, b, c = l[i] -    s[a - 1][b - 1] = c -    s[b - 1][a - 1] = c -for i in range(N): -    s[i][i] = 0 -s = floyd_warshall(s) -# print(s) +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) -for i in itertools.permutations(r): -    #    print(i) -    temp_ans = 0 -    for j in range(R - 1): -        temp_ans += s[i[j] - 1][i[j + 1] - 1] -    ans = min(ans, temp_ans) +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)