import itertools

import heapq



V, E, R = [int(_) for _ in input().split()]

r = [int(_) - 1 for _ in input().split()]  # 0-indexed

G = {}

for i in range(V):

    G[i] = {}

    G[i][i] = 0



for _ in range(E):

    s, t, c = [int(_) for _ in input().split()]

    s -= 1  # 0-indexed

    t -= 1  # 0-indexed

    G[s][t] = c

    G[t][s] = c



INF = float('inf')



Ds = []

for r_index in range(R):

    que = []

    d = 0

    i = r[r_index]

    D = [INF] * V

    D[i] = 0

    used = [False] * V

    used[i] = True



    while True:

        for j in list(G[i].keys()):

            heapq.heappush(que, (d + G[i][j], j))

        v = -1

        while que:

            d, j = heapq.heappop(que)

            if not used[j]:

                v = j

                break

        if v == -1:

            break

        else:

            used[v] = True

            D[v] = d

            i = v

    Ds += [D]

ans = INF

for array in itertools.permutations(list(range(R)), R):

    d = 0

    for i in range(R - 1):

        d += Ds[array[i]][r[array[i + 1]]]

    ans = min(ans, d)

print(ans)
import numpy as np

from scipy.sparse import csr_matrix

from scipy.sparse.csgraph import floyd_warshall

import itertools

I = [int(_) for _ in open(0).read().split()]

N, M, R = I[:3]

r = np.array(I[3:3 + R])

ABC = I[3 + R:]

F = floyd_warshall(csr_matrix((ABC[2::3], (ABC[::3], ABC[1::3])), (N + 1, N + 1)), 0).astype(np.int64)

ans = float('inf')

for root in itertools.permutations(r, R):

    ans = min(ans, sum(F[i,j] for i, j in zip(root, root[1:])))

print(ans)

import itertools
import heapq

V, E, R = [int(_) for _ in input().split()]
r = [int(_) - 1 for _ in input().split()]  # 0-indexed
G = {}
for i in range(V):
    G[i] = {}
    G[i][i] = 0
for _ in range(E):
    s, t, c = [int(_) for _ in input().split()]
    s -= 1  # 0-indexed
    t -= 1  # 0-indexed
    G[s][t] = c
    G[t][s] = c
INF = float("inf")
Ds = []
for r_index in range(R):
    que = []
    d = 0
    i = r[r_index]
    D = [INF] * V
    D[i] = 0
    used = [False] * V
    used[i] = True
    while True:
        for j in list(G[i].keys()):
            heapq.heappush(que, (d + G[i][j], j))
        v = -1
        while que:
            d, j = heapq.heappop(que)
            if not used[j]:
                v = j
                break
        if v == -1:
            break
        else:
            used[v] = True
            D[v] = d
            i = v
    Ds += [D]
ans = INF
for array in itertools.permutations(list(range(R)), R):
    d = 0
    for i in range(R - 1):
        d += Ds[array[i]][r[array[i + 1]]]
    ans = min(ans, d)
print(ans)

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

I = [int(_) for _ in open(0).read().split()]
N, M, R = I[:3]
r = np.array(I[3 : 3 + R])
ABC = I[3 + R :]
F = floyd_warshall(
    csr_matrix((ABC[2::3], (ABC[::3], ABC[1::3])), (N + 1, N + 1)), 0
).astype(np.int64)
ans = float("inf")
for root in itertools.permutations(r, R):
    ans = min(ans, sum(F[i, j] for i, j in zip(root, root[1:])))
print(ans)

+import numpy as np +from scipy.sparse import csr_matrix +from scipy.sparse.csgraph import floyd_warshall -import heapq -V, E, R = [int(_) for _ in input().split()] -r = [int(_) - 1 for _ in input().split()]  # 0-indexed -G = {} -for i in range(V): -    G[i] = {} -    G[i][i] = 0 -for _ in range(E): -    s, t, c = [int(_) for _ in input().split()] -    s -= 1  # 0-indexed -    t -= 1  # 0-indexed -    G[s][t] = c -    G[t][s] = c -INF = float("inf") -Ds = [] -for r_index in range(R): -    que = [] -    d = 0 -    i = r[r_index] -    D = [INF] * V -    D[i] = 0 -    used = [False] * V -    used[i] = True -    while True: -        for j in list(G[i].keys()): -            heapq.heappush(que, (d + G[i][j], j)) -        v = -1 -        while que: -            d, j = heapq.heappop(que) -            if not used[j]: -                v = j -                break -        if v == -1: -            break -        else: -            used[v] = True -            D[v] = d -            i = v -    Ds += [D] -ans = INF -for array in itertools.permutations(list(range(R)), R): -    d = 0 -    for i in range(R - 1): -        d += Ds[array[i]][r[array[i + 1]]] -    ans = min(ans, d) +I = [int(_) for _ in open(0).read().split()] +N, M, R = I[:3] +r = np.array(I[3 : 3 + R]) +ABC = I[3 + R :] +F = floyd_warshall( +    csr_matrix((ABC[2::3], (ABC[::3], ABC[1::3])), (N + 1, N + 1)), 0 +).astype(np.int64) +ans = float("inf") +for root in itertools.permutations(r, R): +    ans = min(ans, sum(F[i, j] for i, j in zip(root, root[1:])))