from scipy.sparse.csgraph import floyd_warshall

import itertools

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

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

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

for i in range(n):

    d[i][i] = 0

for i in range(m):

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

    d[a-1][b-1] = l

    d[b-1][a-1] = l

d = floyd_warshall(d)

ans = float('inf')

seq = []

for i in range(r):

  seq.append(i)

K = list(itertools.permutations(seq))

for i in range(len(K)):

  cur = 0

  for j in range(1,r):

    p = L[K[i][j-1]]-1

    q = L[K[i][j]]-1

    cur += d[p][q]

  if cur != float('inf'):

    if cur <= ans:

      ans = cur

print((int(ans)))
import itertools



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

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

L = []

ans = float('inf')

for i in range(M):

    L.append(list(map(int,input().split())))

cost = []

for i in range(N):

    T = [float('inf') for j in range(N)]

    cost.append(T)

for i in range(M):

    cost[L[i][0]-1][L[i][1]-1] = L[i][2]

    cost[L[i][1]-1][L[i][0]-1] = L[i][2]

for l in range(N):

    for k in range(N):

        for m in range(N):

            cost[k][m] = min(cost[k][l]+cost[l][m], cost[k][m])



junretu = list(itertools.permutations(r))

for i in range(len(junretu)):

    temp = 0

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

        c = junretu[i][j]

        d = junretu[i][j+1]

        temp += cost[c-1][d-1]

    ans = min(ans,temp)

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

n, m, r = list(map(int, input().split()))
L = list(map(int, input().split()))
d = [[float("inf")] * n for i in range(n)]
for i in range(n):
    d[i][i] = 0
for i in range(m):
    a, b, l = list(map(int, input().split()))
    d[a - 1][b - 1] = l
    d[b - 1][a - 1] = l
d = floyd_warshall(d)
ans = float("inf")
seq = []
for i in range(r):
    seq.append(i)
K = list(itertools.permutations(seq))
for i in range(len(K)):
    cur = 0
    for j in range(1, r):
        p = L[K[i][j - 1]] - 1
        q = L[K[i][j]] - 1
        cur += d[p][q]
    if cur != float("inf"):
        if cur <= ans:
            ans = cur
print((int(ans)))

import itertools

N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
L = []
ans = float("inf")
for i in range(M):
    L.append(list(map(int, input().split())))
cost = []
for i in range(N):
    T = [float("inf") for j in range(N)]
    cost.append(T)
for i in range(M):
    cost[L[i][0] - 1][L[i][1] - 1] = L[i][2]
    cost[L[i][1] - 1][L[i][0] - 1] = L[i][2]
for l in range(N):
    for k in range(N):
        for m in range(N):
            cost[k][m] = min(cost[k][l] + cost[l][m], cost[k][m])
junretu = list(itertools.permutations(r))
for i in range(len(junretu)):
    temp = 0
    for j in range(len(r) - 1):
        c = junretu[i][j]
        d = junretu[i][j + 1]
        temp += cost[c - 1][d - 1]
    ans = min(ans, temp)
print(ans)

-from scipy.sparse.csgraph import floyd_warshall -n, m, r = list(map(int, input().split())) -L = list(map(int, input().split())) -d = [[float("inf")] * n for i in range(n)] -for i in range(n): -    d[i][i] = 0 -for i in range(m): -    a, b, l = list(map(int, input().split())) -    d[a - 1][b - 1] = l -    d[b - 1][a - 1] = l -d = floyd_warshall(d) +N, M, R = list(map(int, input().split())) +r = list(map(int, input().split())) +L = [] -seq = [] -for i in range(r): -    seq.append(i) -K = list(itertools.permutations(seq)) -for i in range(len(K)): -    cur = 0 -    for j in range(1, r): -        p = L[K[i][j - 1]] - 1 -        q = L[K[i][j]] - 1 -        cur += d[p][q] -    if cur != float("inf"): -        if cur <= ans: -            ans = cur -print((int(ans))) +for i in range(M): +    L.append(list(map(int, input().split()))) +cost = [] +for i in range(N): +    T = [float("inf") for j in range(N)] +    cost.append(T) +for i in range(M): +    cost[L[i][0] - 1][L[i][1] - 1] = L[i][2] +    cost[L[i][1] - 1][L[i][0] - 1] = L[i][2] +for l in range(N): +    for k in range(N): +        for m in range(N): +            cost[k][m] = min(cost[k][l] + cost[l][m], cost[k][m]) +junretu = list(itertools.permutations(r)) +for i in range(len(junretu)): +    temp = 0 +    for j in range(len(r) - 1): +        c = junretu[i][j] +        d = junretu[i][j + 1] +        temp += cost[c - 1][d - 1] +    ans = min(ans, temp) +print(ans)