import heapq

import itertools



def solve():

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

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

    R = [x-1 for x in R]

    G = [[] for i in range(N)]



    for i in range(M):

        A, B, C = list(map(int, input().split()))

        A -= 1

        B -= 1

        G[A].append((C, B))

        G[B].append((C, A))





    def dijkstra(d):

        que = []



        tar = -1

        for i in range(len(d)):

            if d[i] == -1:

                break

            if d[i] == 0:

                tar = i

            heapq.heappush(que, (d[i], i))



        while len(que) != 0:

            dist, node = heapq.heappop(que)

            for (cost, to) in G[node]:

                if d[to] > d[node] + cost:

                    d[to] = d[node] + cost

                    heapq.heappush(que, (dist + cost, to))



        return d





    ds = [[1e16 for i in range(N)] for j in range(N)]



    for i in range(N):

        ds[i][i] = 0



    for i in range(N):

        ds[i] = dijkstra(ds[i])

        for j in range(N):

            ds[j][i] = ds[i][j]



    res = 1e16

    for r in list(itertools.permutations(R)):

        d = 0

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

            d += ds[r[i]][r[i+1]]

        res = min(res, d)



    return res



print((solve()))
import heapq

import itertools



def solve():

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

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

    R = [x-1 for x in R]

    G = [[] for i in range(N)]



    for i in range(M):

        A, B, C = list(map(int, input().split()))

        A -= 1

        B -= 1

        G[A].append((C, B))

        G[B].append((C, A))





    def dijkstra(d):

        que = []



        tar = -1

        count = set()

        for i in range(len(d)):

            if d[i] == 1e+16:

                break

            if d[i] == 0:

                tar = i

            heapq.heappush(que, (d[i], i))

            count.add(i)



        checked = [False for i in range(N)]



        while len(que) != 0:

            dist, node = heapq.heappop(que)

            if checked[node]:

                continue

            count.add(node)

            if len(count) == N:

                break



            for (cost, to) in G[node]:

                if d[to] > d[node] + cost:

                    d[to] = d[node] + cost

                    heapq.heappush(que, (dist + cost, to))



            checked[node] = True



        return d





    ds = [[1e16 for i in range(N)] for j in range(N)]



    for i in range(N):

        ds[i][i] = 0



    for i in range(N):

        ds[i] = dijkstra(ds[i])

        for j in range(N):

            ds[j][i] = ds[i][j]



    res = 1e16

    for r in list(itertools.permutations(R)):

        d = 0

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

            d += ds[r[i]][r[i+1]]

        res = min(res, d)



    return res



print((solve()))
import heapq
import itertools


def solve():
    N, M, _ = list(map(int, input().split()))
    R = list(map(int, input().split()))
    R = [x - 1 for x in R]
    G = [[] for i in range(N)]
    for i in range(M):
        A, B, C = list(map(int, input().split()))
        A -= 1
        B -= 1
        G[A].append((C, B))
        G[B].append((C, A))

    def dijkstra(d):
        que = []
        tar = -1
        for i in range(len(d)):
            if d[i] == -1:
                break
            if d[i] == 0:
                tar = i
            heapq.heappush(que, (d[i], i))
        while len(que) != 0:
            dist, node = heapq.heappop(que)
            for (cost, to) in G[node]:
                if d[to] > d[node] + cost:
                    d[to] = d[node] + cost
                    heapq.heappush(que, (dist + cost, to))
        return d

    ds = [[1e16 for i in range(N)] for j in range(N)]
    for i in range(N):
        ds[i][i] = 0
    for i in range(N):
        ds[i] = dijkstra(ds[i])
        for j in range(N):
            ds[j][i] = ds[i][j]
    res = 1e16
    for r in list(itertools.permutations(R)):
        d = 0
        for i in range(len(r) - 1):
            d += ds[r[i]][r[i + 1]]
        res = min(res, d)
    return res


print((solve()))

import heapq
import itertools


def solve():
    N, M, _ = list(map(int, input().split()))
    R = list(map(int, input().split()))
    R = [x - 1 for x in R]
    G = [[] for i in range(N)]
    for i in range(M):
        A, B, C = list(map(int, input().split()))
        A -= 1
        B -= 1
        G[A].append((C, B))
        G[B].append((C, A))

    def dijkstra(d):
        que = []
        tar = -1
        count = set()
        for i in range(len(d)):
            if d[i] == 1e16:
                break
            if d[i] == 0:
                tar = i
            heapq.heappush(que, (d[i], i))
            count.add(i)
        checked = [False for i in range(N)]
        while len(que) != 0:
            dist, node = heapq.heappop(que)
            if checked[node]:
                continue
            count.add(node)
            if len(count) == N:
                break
            for (cost, to) in G[node]:
                if d[to] > d[node] + cost:
                    d[to] = d[node] + cost
                    heapq.heappush(que, (dist + cost, to))
            checked[node] = True
        return d

    ds = [[1e16 for i in range(N)] for j in range(N)]
    for i in range(N):
        ds[i][i] = 0
    for i in range(N):
        ds[i] = dijkstra(ds[i])
        for j in range(N):
            ds[j][i] = ds[i][j]
    res = 1e16
    for r in list(itertools.permutations(R)):
        d = 0
        for i in range(len(r) - 1):
            d += ds[r[i]][r[i + 1]]
        res = min(res, d)
    return res


print((solve()))

+        count = set() -            if d[i] == -1: +            if d[i] == 1e16: +            count.add(i) +        checked = [False for i in range(N)] +            if checked[node]: +                continue +            count.add(node) +            if len(count) == N: +                break +            checked[node] = True