import sys

stdin = sys.stdin



def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



from itertools import permutations

from heapq import heappush, heappop



def dijkstra(graph:list, node:int, start:int) -> list:

    # 未探索のノードは距離INF

    INF = float("inf")

    dist = [INF]*node

    

    # 始点ノードの距離を0とし、dfsのためのpriority queを作成

    dist[start] = 0

    heap = [(0,start)]

    searched = [False for _ in range(node)]

    

    # 未探索のノードをpriority queueに入れる

    while heap:

        cost, cur_node = heappop(heap)

        

        if searched[cur_node] or cost > dist[cur_node]:

            continue

        

        for nex_cost, nex_node in graph[cur_node]:

            dist_cand = dist[cur_node] + nex_cost

            if dist_cand < dist[nex_node]:

                dist[nex_node] = dist_cand

                heappush(heap, (dist[nex_node], nex_node))

    

        searched[cur_node] = True

        

        if sum(searched) == node:

            break

    

    return dist



n,m,r = li()

r = list(li_())

graph = [[] for _ in range(n)]

for _ in range(m):

    a,b,c = li()

    a -= 1

    b -= 1

    graph[a].append((c,b))

    graph[b].append((c,a))

    

dists = []

for i in range(n):

    dists.append(dijkstra(graph, n, i))



ans = 2**64-1

for route in permutations(r):

    temp = 0

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

        temp += dists[route[i]][route[i+1]]

        

    ans = min(ans,temp)

    

print(ans)
import sys

stdin = sys.stdin

 

sys.setrecursionlimit(10**5) 

 

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())





from functools import reduce

from itertools import permutations



from heapq import heappush, heappop



def dijkstra(graph:list, node:int, start:int) -> list:

    # 未探索のノードは距離INF

    INF = float("inf")

    dist = [INF]*node

    

    # 始点ノードの距離を0とし、dfsのためのpriority queを作成

    dist[start] = 0

    heap = [(0,start)]

    

    # 未探索のノードをpriority queueに入れる

    while heap:

        cost, cur_node = heappop(heap)

        

        for nex_cost, nex_node in graph[cur_node]:

            dist_cand = dist[cur_node] + nex_cost

            if dist_cand < dist[nex_node]:

                dist[nex_node] = dist_cand

                heappush(heap, (dist[nex_node], nex_node))

    

    return dist



def find_dist(fr: int, to: int):

    return graph[fr][to]



n,m,rn = li()

r = list(li_())

adj_list = [[] for _ in range(n)]

for _ in range(m):

    a,b,c = li()

    a -= 1

    b -= 1

    adj_list[a].append((c, b))

    adj_list[b].append((c, a))

    

graph = [[0]*rn for _ in range(rn)]

for i, ri in enumerate(r):

    dist = dijkstra(adj_list, n, ri)

    for j, rj in enumerate(r):

        graph[i][j] = dist[rj]



ans = float('inf')

for route in permutations(list(range(len(r))), len(r)):

    cand = 0

    for i,j in zip(route[:-1], route[1:]):

        cand += graph[i][j]

    

    ans = min(ans, cand)



print(ans)

import sys

stdin = sys.stdin


def li():
    return list(map(int, stdin.readline().split()))


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


from itertools import permutations
from heapq import heappush, heappop


def dijkstra(graph: list, node: int, start: int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF] * node
    # 始点ノードの距離を0とし、dfsのためのpriority queを作成
    dist[start] = 0
    heap = [(0, start)]
    searched = [False for _ in range(node)]
    # 未探索のノードをpriority queueに入れる
    while heap:
        cost, cur_node = heappop(heap)
        if searched[cur_node] or cost > dist[cur_node]:
            continue
        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heappush(heap, (dist[nex_node], nex_node))
        searched[cur_node] = True
        if sum(searched) == node:
            break
    return dist


n, m, r = li()
r = list(li_())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = li()
    a -= 1
    b -= 1
    graph[a].append((c, b))
    graph[b].append((c, a))
dists = []
for i in range(n):
    dists.append(dijkstra(graph, n, i))
ans = 2**64 - 1
for route in permutations(r):
    temp = 0
    for i in range(len(route) - 1):
        temp += dists[route[i]][route[i + 1]]
    ans = min(ans, temp)
print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


def li():
    return list(map(int, stdin.readline().split()))


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


from functools import reduce
from itertools import permutations
from heapq import heappush, heappop


def dijkstra(graph: list, node: int, start: int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF] * node
    # 始点ノードの距離を0とし、dfsのためのpriority queを作成
    dist[start] = 0
    heap = [(0, start)]
    # 未探索のノードをpriority queueに入れる
    while heap:
        cost, cur_node = heappop(heap)
        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heappush(heap, (dist[nex_node], nex_node))
    return dist


def find_dist(fr: int, to: int):
    return graph[fr][to]


n, m, rn = li()
r = list(li_())
adj_list = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = li()
    a -= 1
    b -= 1
    adj_list[a].append((c, b))
    adj_list[b].append((c, a))
graph = [[0] * rn for _ in range(rn)]
for i, ri in enumerate(r):
    dist = dijkstra(adj_list, n, ri)
    for j, rj in enumerate(r):
        graph[i][j] = dist[rj]
ans = float("inf")
for route in permutations(list(range(len(r))), len(r)):
    cand = 0
    for i, j in zip(route[:-1], route[1:]):
        cand += graph[i][j]
    ans = min(ans, cand)
print(ans)

+sys.setrecursionlimit(10**5) +from functools import reduce -    searched = [False for _ in range(node)] -        if searched[cur_node] or cost > dist[cur_node]: -            continue -        searched[cur_node] = True -        if sum(searched) == node: -            break -n, m, r = li() +def find_dist(fr: int, to: int): +    return graph[fr][to] + + +n, m, rn = li() -graph = [[] for _ in range(n)] +adj_list = [[] for _ in range(n)] -    graph[a].append((c, b)) -    graph[b].append((c, a)) -dists = [] -for i in range(n): -    dists.append(dijkstra(graph, n, i)) -ans = 2**64 - 1 -for route in permutations(r): -    temp = 0 -    for i in range(len(route) - 1): -        temp += dists[route[i]][route[i + 1]] -    ans = min(ans, temp) +    adj_list[a].append((c, b)) +    adj_list[b].append((c, a)) +graph = [[0] * rn for _ in range(rn)] +for i, ri in enumerate(r): +    dist = dijkstra(adj_list, n, ri) +    for j, rj in enumerate(r): +        graph[i][j] = dist[rj] +ans = float("inf") +for route in permutations(list(range(len(r))), len(r)): +    cand = 0 +    for i, j in zip(route[:-1], route[1:]): +        cand += graph[i][j] +    ans = min(ans, cand)