# ワーシャルフロイドで、各町間の最短距離の更新は200^3 = 8,000,000

# 訪れるべき町Rはたかだか8個なので、順番の全通りを試して8! = 約40000通り



import numpy as np

from scipy.sparse.csgraph import shortest_path, floyd_warshall

from scipy.sparse import csr_matrix



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

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

r = list([x-1 for x in r])



E = [[0 for j in range(N)] for i in range(N)]

for i in range(M):

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

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

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



E = np.array(E)

E = shortest_path(E,method = "FW")



# DFSですべての数を試す

stack = []

for i in range(len(r)):

  stack.append([r[i],[],0])

ans = 10 ** 18

while stack:

  v,visited,dist = stack.pop()

  if len(visited) != 0:

    dist += E[visited[-1]][v]

  visited2 = visited.copy()

  visited2.append(v)

  if len(visited2) == len(r):

    if dist < ans:

      ans = dist

    continue

  for i in range(len(r)):

    if r[i] not in visited2:

      stack.append([r[i],visited2,dist])

    

print((int(ans)))
import sys

readline = sys.stdin.readline



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

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

INF = 10 ** 10



G = [[INF] * N for i in range(N)]

for i in range(M):

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

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

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

  

for i in range(N):

  G[i][i] = 0

  

for k in range(N):

  for i in range(N):

    for j in range(N):

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

      

import itertools

ans = INF

for perm in itertools.permutations(list(range(R))):

  dist = 0

  for i in range(1, len(perm)):

    dist += G[r[perm[i - 1]] - 1][r[perm[i]] - 1]

  if ans > dist:

    ans = dist

    

print(ans)

# ワーシャルフロイドで、各町間の最短距離の更新は200^3 = 8,000,000
# 訪れるべき町Rはたかだか8個なので、順番の全通りを試して8! = 約40000通り
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall
from scipy.sparse import csr_matrix

N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
r = list([x - 1 for x in r])
E = [[0 for j in range(N)] for i in range(N)]
for i in range(M):
    a, b, c = list(map(int, input().split()))
    E[a - 1][b - 1] = c
    E[b - 1][a - 1] = c
E = np.array(E)
E = shortest_path(E, method="FW")
# DFSですべての数を試す
stack = []
for i in range(len(r)):
    stack.append([r[i], [], 0])
ans = 10**18
while stack:
    v, visited, dist = stack.pop()
    if len(visited) != 0:
        dist += E[visited[-1]][v]
    visited2 = visited.copy()
    visited2.append(v)
    if len(visited2) == len(r):
        if dist < ans:
            ans = dist
        continue
    for i in range(len(r)):
        if r[i] not in visited2:
            stack.append([r[i], visited2, dist])
print((int(ans)))

import sys

readline = sys.stdin.readline
N, M, R = list(map(int, readline().split()))
r = list(map(int, readline().split()))
INF = 10**10
G = [[INF] * N for i in range(N)]
for i in range(M):
    a, b, c = list(map(int, readline().split()))
    G[a - 1][b - 1] = c
    G[b - 1][a - 1] = c
for i in range(N):
    G[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])
import itertools

ans = INF
for perm in itertools.permutations(list(range(R))):
    dist = 0
    for i in range(1, len(perm)):
        dist += G[r[perm[i - 1]] - 1][r[perm[i]] - 1]
    if ans > dist:
        ans = dist
print(ans)

-# ワーシャルフロイドで、各町間の最短距離の更新は200^3 = 8,000,000 -# 訪れるべき町Rはたかだか8個なので、順番の全通りを試して8! = 約40000通り -import numpy as np -from scipy.sparse.csgraph import shortest_path, floyd_warshall -from scipy.sparse import csr_matrix +import sys -N, M, R = list(map(int, input().split())) -r = list(map(int, input().split())) -r = list([x - 1 for x in r]) -E = [[0 for j in range(N)] for i in range(N)] +readline = sys.stdin.readline +N, M, R = list(map(int, readline().split())) +r = list(map(int, readline().split())) +INF = 10**10 +G = [[INF] * N for i in range(N)] -    a, b, c = list(map(int, input().split())) -    E[a - 1][b - 1] = c -    E[b - 1][a - 1] = c -E = np.array(E) -E = shortest_path(E, method="FW") -# DFSですべての数を試す -stack = [] -for i in range(len(r)): -    stack.append([r[i], [], 0]) -ans = 10**18 -while stack: -    v, visited, dist = stack.pop() -    if len(visited) != 0: -        dist += E[visited[-1]][v] -    visited2 = visited.copy() -    visited2.append(v) -    if len(visited2) == len(r): -        if dist < ans: -            ans = dist -        continue -    for i in range(len(r)): -        if r[i] not in visited2: -            stack.append([r[i], visited2, dist]) -print((int(ans))) +    a, b, c = list(map(int, readline().split())) +    G[a - 1][b - 1] = c +    G[b - 1][a - 1] = c +for i in range(N): +    G[i][i] = 0 +for k in range(N): +    for i in range(N): +        for j in range(N): +            G[i][j] = min(G[i][j], G[i][k] + G[k][j]) +import itertools + +ans = INF +for perm in itertools.permutations(list(range(R))): +    dist = 0 +    for i in range(1, len(perm)): +        dist += G[r[perm[i - 1]] - 1][r[perm[i]] - 1] +    if ans > dist: +        ans = dist +print(ans)