import numpy as np

from scipy.sparse import csr_matrix

from scipy.sparse.csgraph import floyd_warshall

from itertools import permutations



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

r = list(input().split())

edge = np.array([input().split() for _ in range(M)], dtype = np.int64).T

graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))



lst = floyd_warshall(graph, directed = False)

# print (lst)

def calc(path):

    cost = 0

    s = int(path[0]) - 1

    for i in range(1, R):

        g = int(path[i]) - 1

        cost += lst[s, g]

        s = g

    return cost



ans = 10 ** 18

for tmp in permutations(r):

    # print (tmp)

    ans = min(ans, calc(tmp))



print((int(ans)))
import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 9)

MOD = 10 ** 9 + 7



from itertools import permutations



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

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



INF = 10 ** 9



G = [[INF] * (N + 1) for _ in range(N + 1)]

for i in range(N + 1):

    G[i][i] = 0



for _ in range(M):

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

    G[A][B] = C

    G[B][A] = C



for k in range(N + 1):

    for i in range(N + 1):

        for j in range(N + 1):

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



ans = INF

for tmp in permutations(R):

    score = 0

    for i in range(r - 1):

        score += G[tmp[i]][tmp[i + 1]]

    ans = min(ans, score)



print (ans)

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

N, M, R = list(map(int, input().split()))
r = list(input().split())
edge = np.array([input().split() for _ in range(M)], dtype=np.int64).T
graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))
lst = floyd_warshall(graph, directed=False)
# print (lst)
def calc(path):
    cost = 0
    s = int(path[0]) - 1
    for i in range(1, R):
        g = int(path[i]) - 1
        cost += lst[s, g]
        s = g
    return cost


ans = 10**18
for tmp in permutations(r):
    # print (tmp)
    ans = min(ans, calc(tmp))
print((int(ans)))

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9 + 7
from itertools import permutations

N, M, r = list(map(int, input().split()))
R = list(map(int, input().split()))
INF = 10**9
G = [[INF] * (N + 1) for _ in range(N + 1)]
for i in range(N + 1):
    G[i][i] = 0
for _ in range(M):
    A, B, C = list(map(int, input().split()))
    G[A][B] = C
    G[B][A] = C
for k in range(N + 1):
    for i in range(N + 1):
        for j in range(N + 1):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])
ans = INF
for tmp in permutations(R):
    score = 0
    for i in range(r - 1):
        score += G[tmp[i]][tmp[i + 1]]
    ans = min(ans, score)
print(ans)

-import numpy as np -from scipy.sparse import csr_matrix -from scipy.sparse.csgraph import floyd_warshall +import sys + +input = sys.stdin.readline +sys.setrecursionlimit(10**9) +MOD = 10**9 + 7 -N, M, R = list(map(int, input().split())) -r = list(input().split()) -edge = np.array([input().split() for _ in range(M)], dtype=np.int64).T -graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N)) -lst = floyd_warshall(graph, directed=False) -# print (lst) -def calc(path): -    cost = 0 -    s = int(path[0]) - 1 -    for i in range(1, R): -        g = int(path[i]) - 1 -        cost += lst[s, g] -        s = g -    return cost - - -ans = 10**18 -for tmp in permutations(r): -    # print (tmp) -    ans = min(ans, calc(tmp)) -print((int(ans))) +N, M, r = list(map(int, input().split())) +R = list(map(int, input().split())) +INF = 10**9 +G = [[INF] * (N + 1) for _ in range(N + 1)] +for i in range(N + 1): +    G[i][i] = 0 +for _ in range(M): +    A, B, C = list(map(int, input().split())) +    G[A][B] = C +    G[B][A] = C +for k in range(N + 1): +    for i in range(N + 1): +        for j in range(N + 1): +            G[i][j] = min(G[i][j], G[i][k] + G[k][j]) +ans = INF +for tmp in permutations(R): +    score = 0 +    for i in range(r - 1): +        score += G[tmp[i]][tmp[i + 1]] +    ans = min(ans, score) +print(ans)