from itertools import*



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

*R,=list(map(int,input().split()))

INF=float("inf")

d=[[INF]*n for _ in range(n)]

r=range

for i in r(n):

	d[i][i]=0

for _ in r(m):

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

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

for k in r(n):

	for i in r(n):

		for j in r(n):

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

v=[[d[i-1][j-1]for j in R]for i in R]

m=INF

for t in permutations(r(o)):

	a=0;f=1

	for i,j in zip(t,t[1:]):

		if v[i][j]==INF:

			f=0

			break

		else:

			a+=v[i][j]

	if f:

		m=min(m,a)

print(m)
from scipy.sparse import csr_matrix

from scipy.sparse.csgraph import floyd_warshall

from itertools import permutations

n,m,r,*L=list(map(int,open(0).read().split()))

f=floyd_warshall(csr_matrix((L[r+2::3],(L[r::3],L[r+1::3])),(n+1,n+1)),0)

print((int(min(sum(f[s,t]for s,t in zip(o,o[1:]))for o in permutations(L[:r])))))
from itertools import *

n, m, o = list(map(int, input().split()))
(*R,) = list(map(int, input().split()))
INF = float("inf")
d = [[INF] * n for _ in range(n)]
r = range
for i in r(n):
    d[i][i] = 0
for _ in r(m):
    a, b, c = list(map(int, input().split()))
    d[a - 1][b - 1] = d[b - 1][a - 1] = c
for k in r(n):
    for i in r(n):
        for j in r(n):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])
v = [[d[i - 1][j - 1] for j in R] for i in R]
m = INF
for t in permutations(r(o)):
    a = 0
    f = 1
    for i, j in zip(t, t[1:]):
        if v[i][j] == INF:
            f = 0
            break
        else:
            a += v[i][j]
    if f:
        m = min(m, a)
print(m)

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

n, m, r, *L = list(map(int, open(0).read().split()))
f = floyd_warshall(
    csr_matrix((L[r + 2 :: 3], (L[r::3], L[r + 1 :: 3])), (n + 1, n + 1)), 0
)
print((int(min(sum(f[s, t] for s, t in zip(o, o[1:])) for o in permutations(L[:r])))))

-from itertools import * +from scipy.sparse import csr_matrix +from scipy.sparse.csgraph import floyd_warshall +from itertools import permutations -n, m, o = list(map(int, input().split())) -(*R,) = list(map(int, input().split())) -INF = float("inf") -d = [[INF] * n for _ in range(n)] -r = range -for i in r(n): -    d[i][i] = 0 -for _ in r(m): -    a, b, c = list(map(int, input().split())) -    d[a - 1][b - 1] = d[b - 1][a - 1] = c -for k in r(n): -    for i in r(n): -        for j in r(n): -            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) -v = [[d[i - 1][j - 1] for j in R] for i in R] -m = INF -for t in permutations(r(o)): -    a = 0 -    f = 1 -    for i, j in zip(t, t[1:]): -        if v[i][j] == INF: -            f = 0 -            break -        else: -            a += v[i][j] -    if f: -        m = min(m, a) -print(m) +n, m, r, *L = list(map(int, open(0).read().split())) +f = floyd_warshall( +    csr_matrix((L[r + 2 :: 3], (L[r::3], L[r + 1 :: 3])), (n + 1, n + 1)), 0 +) +print((int(min(sum(f[s, t] for s, t in zip(o, o[1:])) for o in permutations(L[:r])))))