from itertools import permutations, product

from scipy.sparse.csgraph import floyd_warshall

from scipy.sparse import csr_matrix



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

r = [int(x) for x in input().split()]

abc = [[int(x) for x in input().split()] for _ in range(M)]



dist = [[float('inf') for _ in range(N)] for _ in range(N)]

A, B, C = [0] * M, [0] * M, [0] * M

for i in range(M):

    a, b, c = abc[i]

    A[i] = a - 1

    B[i] = b - 1

    C[i] = c



g = csr_matrix((C, (A, B)), shape=(N, N), dtype=int)

dist = floyd_warshall(g, directed=False)



ans = float('inf')

for route in permutations(r):

    d = 0

    for i in range(R - 1):

        s = route[i] - 1

        g = route[i + 1] - 1

        d += int(dist[s][g])

    ans = min(ans, d)

print(ans)
from itertools import permutations, product

from collections import defaultdict

from heapq import heappop, heappush



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

r = [int(x) for x in input().split()]

abc = [[int(x) for x in input().split()] for _ in range(M)]





class Graph(object):

    def __init__(self):

        self.graph = defaultdict(list)



    def __len__(self):

        return len(self.graph)



    def add_edge(self, src, dst, weight=1):

        self.graph[src].append((dst, weight))



    def get_nodes(self):

        return list(self.graph.keys())





class Dijkstra(object):

    def __init__(self, graph, start):

        g = graph.graph



        self.dist = defaultdict(lambda: float('inf'))

        self.dist[start] = 0

        self.prev = defaultdict(lambda: None)



        Q = []

        heappush(Q, (self.dist[start], start))



        while Q:

            dist_u, u = heappop(Q)

            if self.dist[u] < dist_u:

                continue

            for v, weight in g[u]:

                alt = dist_u + weight

                if self.dist[v] > alt:

                    self.dist[v] = alt

                    self.prev[v] = u

                    heappush(Q, (alt, v))



    def shortest_distance(self, goal):

        return self.dist[goal]



    def shortest_path(self, goal):

        path = []

        node = goal

        while node is not None:

            path.append(node)

            node = self.prev[node]

        return path[::-1]





g = Graph()

for a, b, c in abc:

    g.add_edge(a - 1, b - 1, c)

    g.add_edge(b - 1, a - 1, c)



D = dict()

for ri in r:

    D[ri - 1] = Dijkstra(g, ri - 1)



ans = float('inf')

for route in permutations(r):

    d = 0

    for i in range(R - 1):

        s = route[i] - 1

        g = route[i + 1] - 1

        d += int(D[s].shortest_distance(g))

    ans = min(ans, d)

print(ans)
from itertools import permutations, product
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N, M, R = list(map(int, input().split()))
r = [int(x) for x in input().split()]
abc = [[int(x) for x in input().split()] for _ in range(M)]
dist = [[float("inf") for _ in range(N)] for _ in range(N)]
A, B, C = [0] * M, [0] * M, [0] * M
for i in range(M):
    a, b, c = abc[i]
    A[i] = a - 1
    B[i] = b - 1
    C[i] = c
g = csr_matrix((C, (A, B)), shape=(N, N), dtype=int)
dist = floyd_warshall(g, directed=False)
ans = float("inf")
for route in permutations(r):
    d = 0
    for i in range(R - 1):
        s = route[i] - 1
        g = route[i + 1] - 1
        d += int(dist[s][g])
    ans = min(ans, d)
print(ans)

from itertools import permutations, product
from collections import defaultdict
from heapq import heappop, heappush

N, M, R = list(map(int, input().split()))
r = [int(x) for x in input().split()]
abc = [[int(x) for x in input().split()] for _ in range(M)]


class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return list(self.graph.keys())


class Dijkstra(object):
    def __init__(self, graph, start):
        g = graph.graph
        self.dist = defaultdict(lambda: float("inf"))
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)
        Q = []
        heappush(Q, (self.dist[start], start))
        while Q:
            dist_u, u = heappop(Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(Q, (alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


g = Graph()
for a, b, c in abc:
    g.add_edge(a - 1, b - 1, c)
    g.add_edge(b - 1, a - 1, c)
D = dict()
for ri in r:
    D[ri - 1] = Dijkstra(g, ri - 1)
ans = float("inf")
for route in permutations(r):
    d = 0
    for i in range(R - 1):
        s = route[i] - 1
        g = route[i + 1] - 1
        d += int(D[s].shortest_distance(g))
    ans = min(ans, d)
print(ans)

-from scipy.sparse.csgraph import floyd_warshall -from scipy.sparse import csr_matrix +from collections import defaultdict +from heapq import heappop, heappush -dist = [[float("inf") for _ in range(N)] for _ in range(N)] -A, B, C = [0] * M, [0] * M, [0] * M -for i in range(M): -    a, b, c = abc[i] -    A[i] = a - 1 -    B[i] = b - 1 -    C[i] = c -g = csr_matrix((C, (A, B)), shape=(N, N), dtype=int) -dist = floyd_warshall(g, directed=False) + + +class Graph(object): +    def __init__(self): +        self.graph = defaultdict(list) + +    def __len__(self): +        return len(self.graph) + +    def add_edge(self, src, dst, weight=1): +        self.graph[src].append((dst, weight)) + +    def get_nodes(self): +        return list(self.graph.keys()) + + +class Dijkstra(object): +    def __init__(self, graph, start): +        g = graph.graph +        self.dist = defaultdict(lambda: float("inf")) +        self.dist[start] = 0 +        self.prev = defaultdict(lambda: None) +        Q = [] +        heappush(Q, (self.dist[start], start)) +        while Q: +            dist_u, u = heappop(Q) +            if self.dist[u] < dist_u: +                continue +            for v, weight in g[u]: +                alt = dist_u + weight +                if self.dist[v] > alt: +                    self.dist[v] = alt +                    self.prev[v] = u +                    heappush(Q, (alt, v)) + +    def shortest_distance(self, goal): +        return self.dist[goal] + +    def shortest_path(self, goal): +        path = [] +        node = goal +        while node is not None: +            path.append(node) +            node = self.prev[node] +        return path[::-1] + + +g = Graph() +for a, b, c in abc: +    g.add_edge(a - 1, b - 1, c) +    g.add_edge(b - 1, a - 1, c) +D = dict() +for ri in r: +    D[ri - 1] = Dijkstra(g, ri - 1) -        d += int(dist[s][g]) +        d += int(D[s].shortest_distance(g))