from itertools import permutations

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

r = [int(c)-1 for c in input().split()]

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

for i in range(M):

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

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

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

def warshall_floyd(d,n):

    #d[i][j]: iからjへの最短距離

    for k in range(n):

        for i in range(n):

            for j in range(n):

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

    return d

dist = warshall_floyd(cost,N)

ls = list(permutations(r))

ans = -1

for l in ls:

  m = 0

  p = l[0]

  flag = False

  for q in l[1:]:

    m += dist[p][q]

    p = q

  if ans==-1 or ans>m:

    ans = m

print(ans)
from itertools import permutations

N, M, R, *L = list(map(int, open(0).read().split()))

city = L[:R]

inf = L[R:]

dist = [[10**10]*N for i in range(N)]

for x,y,c in zip(*[iter(inf)]*3):

  dist[x-1][y-1] = c

  dist[y-1][x-1] = c

for i in range(N):

  dist[i][i] = 0



for k in range(N):

  for i in range(N):

    for j in range(N):

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



ans = 10**10

for m in permutations(city):

  n = 0

  for i in range(R-1):

    n += dist[m[i]-1][m[i+1]-1]

  ans = min(ans,n)

print(ans)  

  

from itertools import permutations

N, M, R = list(map(int, input().split()))
r = [int(c) - 1 for c in input().split()]
cost = [[float("inf")] * N for i in range(N)]
for i in range(M):
    a, b, c = list(map(int, input().split()))
    cost[a - 1][b - 1] = c
    cost[b - 1][a - 1] = c


def warshall_floyd(d, n):
    # d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


dist = warshall_floyd(cost, N)
ls = list(permutations(r))
ans = -1
for l in ls:
    m = 0
    p = l[0]
    flag = False
    for q in l[1:]:
        m += dist[p][q]
        p = q
    if ans == -1 or ans > m:
        ans = m
print(ans)

from itertools import permutations

N, M, R, *L = list(map(int, open(0).read().split()))
city = L[:R]
inf = L[R:]
dist = [[10**10] * N for i in range(N)]
for x, y, c in zip(*[iter(inf)] * 3):
    dist[x - 1][y - 1] = c
    dist[y - 1][x - 1] = c
for i in range(N):
    dist[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j])
ans = 10**10
for m in permutations(city):
    n = 0
    for i in range(R - 1):
        n += dist[m[i] - 1][m[i + 1] - 1]
    ans = min(ans, n)
print(ans)

-N, M, R = list(map(int, input().split())) -r = [int(c) - 1 for c in input().split()] -cost = [[float("inf")] * N for i in range(N)] -for i in range(M): -    a, b, c = list(map(int, input().split())) -    cost[a - 1][b - 1] = c -    cost[b - 1][a - 1] = c - - -def warshall_floyd(d, n): -    # d[i][j]: iからjへの最短距離 -    for k in range(n): -        for i in range(n): -            for j in range(n): -                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) -    return d - - -dist = warshall_floyd(cost, N) -ls = list(permutations(r)) -ans = -1 -for l in ls: -    m = 0 -    p = l[0] -    flag = False -    for q in l[1:]: -        m += dist[p][q] -        p = q -    if ans == -1 or ans > m: -        ans = m +N, M, R, *L = list(map(int, open(0).read().split())) +city = L[:R] +inf = L[R:] +dist = [[10**10] * N for i in range(N)] +for x, y, c in zip(*[iter(inf)] * 3): +    dist[x - 1][y - 1] = c +    dist[y - 1][x - 1] = c +for i in range(N): +    dist[i][i] = 0 +for k in range(N): +    for i in range(N): +        for j in range(N): +            dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]) +ans = 10**10 +for m in permutations(city): +    n = 0 +    for i in range(R - 1): +        n += dist[m[i] - 1][m[i + 1] - 1] +    ans = min(ans, n)