from itertools import permutations

INFTY = 10**8

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

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

G = {i:[] for i in range(1,N+1)}

for _ in range(M):

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

    G[a].append((b,c))

    G[b].append((a,c))

d = {i:[INFTY for _ in range(N+1)] for i in range(N+1)}

for i in G:

    d[i][i] = 0

    for x in G[i]:

        d[i][x[0]] = x[1] 

for k in range(1,N+1):

    for i in range(1,N+1):

        for j in range(1,N+1):

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

dmin = INFTY

for x in permutations(list(range(R)),R):

    cnt = 0

    for i in range(R-1):

        cnt += d[A[x[i]]][A[x[i+1]]]

    dmin = min(dmin,cnt)

print(dmin)
from itertools import permutations

INFTY = 10**8

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

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

G = {i:[] for i in range(1,N+1)}

for _ in range(M):

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

    G[a].append((b,c))

    G[b].append((a,c))

dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)]

for i in range(1,N+1):

    dist[i][i] = 0

for i in range(1,N+1):

    for j,d in G[i]:

        dist[i][j] = d

for k in range(1,N+1):

    for i in range(1,N+1):

        for j in range(1,N+1):

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

dmin = 10**8

for x in permutations(list(range(R)),R):

    d = 0

    for k in range(1,R):

        d += dist[r[x[k]]][r[x[k-1]]]

    dmin = min(dmin,d)

print(dmin)
from itertools import permutations

INFTY = 10**8
N, M, R = list(map(int, input().split()))
A = list(map(int, input().split()))
G = {i: [] for i in range(1, N + 1)}
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    G[a].append((b, c))
    G[b].append((a, c))
d = {i: [INFTY for _ in range(N + 1)] for i in range(N + 1)}
for i in G:
    d[i][i] = 0
    for x in G[i]:
        d[i][x[0]] = x[1]
for k in range(1, N + 1):
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])
dmin = INFTY
for x in permutations(list(range(R)), R):
    cnt = 0
    for i in range(R - 1):
        cnt += d[A[x[i]]][A[x[i + 1]]]
    dmin = min(dmin, cnt)
print(dmin)

from itertools import permutations

INFTY = 10**8
N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
G = {i: [] for i in range(1, N + 1)}
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    G[a].append((b, c))
    G[b].append((a, c))
dist = [[INFTY for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(1, N + 1):
    dist[i][i] = 0
for i in range(1, N + 1):
    for j, d in G[i]:
        dist[i][j] = d
for k in range(1, N + 1):
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
dmin = 10**8
for x in permutations(list(range(R)), R):
    d = 0
    for k in range(1, R):
        d += dist[r[x[k]]][r[x[k - 1]]]
    dmin = min(dmin, d)
print(dmin)

-A = list(map(int, input().split())) +r = list(map(int, input().split())) -d = {i: [INFTY for _ in range(N + 1)] for i in range(N + 1)} -for i in G: -    d[i][i] = 0 -    for x in G[i]: -        d[i][x[0]] = x[1] +dist = [[INFTY for _ in range(N + 1)] for _ in range(N + 1)] +for i in range(1, N + 1): +    dist[i][i] = 0 +for i in range(1, N + 1): +    for j, d in G[i]: +        dist[i][j] = d -            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) -dmin = INFTY +            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) +dmin = 10**8 -    cnt = 0 -    for i in range(R - 1): -        cnt += d[A[x[i]]][A[x[i + 1]]] -    dmin = min(dmin, cnt) +    d = 0 +    for k in range(1, R): +        d += dist[r[x[k]]][r[x[k - 1]]] +    dmin = min(dmin, d)