n, m, r = list(map(int, input().split()))  # n:頂点数　w:辺の数

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

graph = [[float('inf')]*n for i in range(n)]

for _ in range(m):

    u, v, w = list(map(int, input().split()))

    graph[u-1][v-1] = w

    graph[v-1][u-1] = w

for i in range(n):

    graph[i][i] = 0



def warshall_floyd(d):

    # d[i][j] : i から j への最短距離

    for k in range(n):

        for i in range(n):

            for j in range(n):

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

    return d





from itertools import permutations



adj_m=warshall_floyd(graph)

ans=float('inf')

for path in permutations(r_list):

    tmp_dist=0

    for i in range(r-1):

        tmp_dist+=adj_m[path[i]-1][path[i+1]-1]

    ans=min(ans, tmp_dist)

print(ans)

from collections import defaultdict

from itertools import permutations

import heapq



INF = float('inf')

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

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



Adj_list = defaultdict(set)



for i in range(M):

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

    Adj_list[a-1].add((b-1, c))

    Adj_list[b-1].add((a-1, c))





def dijkstra(x, vertex):

    d = [INF] * x

    d[vertex] = 0

    hq = [(0, vertex)]

    

    while hq:

        u = heapq.heappop(hq)[1]

        for (v, c) in Adj_list[u]:

            if d[v] > d[u] + c:

                d[v] = d[u] + c

                heapq.heappush(hq, (d[u]+c, v))



    return d



ans = INF

t_dis = 0



table = {}

for i in r:

    table[i-1] = dijkstra(N, i-1)



for each in permutations(r):

    t_dis = 0

    for i in range(R-1):

        t_dis += table[each[i]-1][each[i+1]-1]



    ans = min(ans, t_dis)



print(ans)
n, m, r = list(map(int, input().split()))  # n:頂点数　w:辺の数
r_list = list(map(int, input().split()))
graph = [[float("inf")] * n for i in range(n)]
for _ in range(m):
    u, v, w = list(map(int, input().split()))
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w
for i in range(n):
    graph[i][i] = 0


def warshall_floyd(d):
    # d[i][j] : i から j への最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


from itertools import permutations

adj_m = warshall_floyd(graph)
ans = float("inf")
for path in permutations(r_list):
    tmp_dist = 0
    for i in range(r - 1):
        tmp_dist += adj_m[path[i] - 1][path[i + 1] - 1]
    ans = min(ans, tmp_dist)
print(ans)

from collections import defaultdict
from itertools import permutations
import heapq

INF = float("inf")
N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
Adj_list = defaultdict(set)
for i in range(M):
    a, b, c = list(map(int, input().split()))
    Adj_list[a - 1].add((b - 1, c))
    Adj_list[b - 1].add((a - 1, c))


def dijkstra(x, vertex):
    d = [INF] * x
    d[vertex] = 0
    hq = [(0, vertex)]
    while hq:
        u = heapq.heappop(hq)[1]
        for (v, c) in Adj_list[u]:
            if d[v] > d[u] + c:
                d[v] = d[u] + c
                heapq.heappush(hq, (d[u] + c, v))
    return d


ans = INF
t_dis = 0
table = {}
for i in r:
    table[i - 1] = dijkstra(N, i - 1)
for each in permutations(r):
    t_dis = 0
    for i in range(R - 1):
        t_dis += table[each[i] - 1][each[i + 1] - 1]
    ans = min(ans, t_dis)
print(ans)

-n, m, r = list(map(int, input().split()))  # n:頂点数　w:辺の数 -r_list = list(map(int, input().split())) -graph = [[float("inf")] * n for i in range(n)] -for _ in range(m): -    u, v, w = list(map(int, input().split())) -    graph[u - 1][v - 1] = w -    graph[v - 1][u - 1] = w -for i in range(n): -    graph[i][i] = 0 +from collections import defaultdict +from itertools import permutations +import heapq + +INF = float("inf") +N, M, R = list(map(int, input().split())) +r = list(map(int, input().split())) +Adj_list = defaultdict(set) +for i in range(M): +    a, b, c = list(map(int, input().split())) +    Adj_list[a - 1].add((b - 1, c)) +    Adj_list[b - 1].add((a - 1, c)) -def warshall_floyd(d): -    # d[i][j] : i から j への最短距離 -    for k in range(n): -        for i in range(n): -            for j in range(n): -                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) +def dijkstra(x, vertex): +    d = [INF] * x +    d[vertex] = 0 +    hq = [(0, vertex)] +    while hq: +        u = heapq.heappop(hq)[1] +        for (v, c) in Adj_list[u]: +            if d[v] > d[u] + c: +                d[v] = d[u] + c +                heapq.heappush(hq, (d[u] + c, v)) -from itertools import permutations - -adj_m = warshall_floyd(graph) -ans = float("inf") -for path in permutations(r_list): -    tmp_dist = 0 -    for i in range(r - 1): -        tmp_dist += adj_m[path[i] - 1][path[i + 1] - 1] -    ans = min(ans, tmp_dist) +ans = INF +t_dis = 0 +table = {} +for i in r: +    table[i - 1] = dijkstra(N, i - 1) +for each in permutations(r): +    t_dis = 0 +    for i in range(R - 1): +        t_dis += table[each[i] - 1][each[i + 1] - 1] +    ans = min(ans, t_dis)