from scipy.sparse.csgraph import dijkstra as di

from itertools import permutations

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

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



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

for i in range(M):

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

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

# for i in range(N):

#     print(route[i])





p_route = di(route)

# print(p_route)



mn = float('INF')

for tmp in permutations(r):

    t_sum = 0

    for i in range(len(tmp)-1):

        t_sum += p_route[tmp[i]-1][tmp[i+1]-1]

    if t_sum < mn:

        mn = t_sum



print((int(mn)))
from itertools import permutations as perm

from scipy.sparse.csgraph import dijkstra as di



def warshall(d, n):

    for k in range(n):

        for i in range(n):

            for j in range(n):

                if d[i][k] + d[k][j] < d[i][j]:

                    d[i][j] = d[i][k] + d[k][j]



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

rr = [i-1 for i in map(int, input().split())]



inf = float('INF')

route = [[0 for j in range(n)] for i in range(n)]

for _ in range(m):

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

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



route = di(route, n)



ans = inf

for tmp in perm(rr):

    cost = 0

    for i in range(r-1):

        cost += route[tmp[i]][tmp[i+1]]

    if cost < ans:

        ans = cost

print((int(ans)))

from scipy.sparse.csgraph import dijkstra as di
from itertools import permutations

N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
route = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    a, b, c = list(map(int, input().split()))
    route[a - 1][b - 1] = route[b - 1][a - 1] = c
# for i in range(N):
#     print(route[i])
p_route = di(route)
# print(p_route)
mn = float("INF")
for tmp in permutations(r):
    t_sum = 0
    for i in range(len(tmp) - 1):
        t_sum += p_route[tmp[i] - 1][tmp[i + 1] - 1]
    if t_sum < mn:
        mn = t_sum
print((int(mn)))

from itertools import permutations as perm
from scipy.sparse.csgraph import dijkstra as di


def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j]


n, m, r = list(map(int, input().split()))
rr = [i - 1 for i in map(int, input().split())]
inf = float("INF")
route = [[0 for j in range(n)] for i in range(n)]
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    route[a - 1][b - 1] = route[b - 1][a - 1] = c
route = di(route, n)
ans = inf
for tmp in perm(rr):
    cost = 0
    for i in range(r - 1):
        cost += route[tmp[i]][tmp[i + 1]]
    if cost < ans:
        ans = cost
print((int(ans)))

+from itertools import permutations as perm -from itertools import permutations -N, M, R = list(map(int, input().split())) -r = list(map(int, input().split())) -route = [[0 for i in range(N)] for j in range(N)] -for i in range(M): + +def warshall(d, n): +    for k in range(n): +        for i in range(n): +            for j in range(n): +                if d[i][k] + d[k][j] < d[i][j]: +                    d[i][j] = d[i][k] + d[k][j] + + +n, m, r = list(map(int, input().split())) +rr = [i - 1 for i in map(int, input().split())] +inf = float("INF") +route = [[0 for j in range(n)] for i in range(n)] +for _ in range(m): -# for i in range(N): -#     print(route[i]) -p_route = di(route) -# print(p_route) -mn = float("INF") -for tmp in permutations(r): -    t_sum = 0 -    for i in range(len(tmp) - 1): -        t_sum += p_route[tmp[i] - 1][tmp[i + 1] - 1] -    if t_sum < mn: -        mn = t_sum -print((int(mn))) +route = di(route, n) +ans = inf +for tmp in perm(rr): +    cost = 0 +    for i in range(r - 1): +        cost += route[tmp[i]][tmp[i + 1]] +    if cost < ans: +        ans = cost +print((int(ans)))