from collections import deque

import itertools

from scipy.sparse.csgraph import floyd_warshall as wf

import sys

input = sys.stdin.readline



MAX = 1e9



def main():

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

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

    link = [[MAX if j != i else 0 for j in range(N+1)] for i in range(N+1)]



    for i in range(M):

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

        link[a][b] = c

        link[b][a] = c



    link = wf(link)



    ans = MAX

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

        tmp = 0

        for i in range(R-1):

            tmp += link[per[i]][per[i+1]]

        ans = min(ans, tmp)

    print((int(ans)))



if __name__ == "__main__":

    main()

from scipy.sparse.csgraph import floyd_warshall as wf

from itertools import permutations

import sys

input = sys.stdin.readline



def main():

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

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



    MAX = int(1e9)

    link = [[MAX if i != j else 0 for j in range(N)] for i in range(N)]



    for i in range(M):

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

        a -= 1

        b -= 1

        link[a][b] = c

        link[b][a] = c

    

    link = wf(link)



    ans = -1

    for t in permutations(r):

        tmp = 0

        for i in range(1, R):

            tmp += link[t[i-1]-1][t[i]-1]

        if ans == -1:

            ans = tmp

        else:

            ans = min(ans, tmp)

    print((int(ans)))



if __name__ == "__main__":

    main()
from collections import deque
import itertools
from scipy.sparse.csgraph import floyd_warshall as wf
import sys

input = sys.stdin.readline
MAX = 1e9


def main():
    N, M, R = list(map(int, input().split()))
    r = list(map(int, input().split()))
    link = [[MAX if j != i else 0 for j in range(N + 1)] for i in range(N + 1)]
    for i in range(M):
        a, b, c = list(map(int, input().split()))
        link[a][b] = c
        link[b][a] = c
    link = wf(link)
    ans = MAX
    for per in list(itertools.permutations(r)):
        tmp = 0
        for i in range(R - 1):
            tmp += link[per[i]][per[i + 1]]
        ans = min(ans, tmp)
    print((int(ans)))


if __name__ == "__main__":
    main()

from scipy.sparse.csgraph import floyd_warshall as wf
from itertools import permutations
import sys

input = sys.stdin.readline


def main():
    N, M, R = list(map(int, input().split()))
    r = list(map(int, input().split()))
    MAX = int(1e9)
    link = [[MAX if i != j else 0 for j in range(N)] for i in range(N)]
    for i in range(M):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        link[a][b] = c
        link[b][a] = c
    link = wf(link)
    ans = -1
    for t in permutations(r):
        tmp = 0
        for i in range(1, R):
            tmp += link[t[i - 1] - 1][t[i] - 1]
        if ans == -1:
            ans = tmp
        else:
            ans = min(ans, tmp)
    print((int(ans)))


if __name__ == "__main__":
    main()

-from collections import deque -import itertools +from itertools import permutations -MAX = 1e9 -    link = [[MAX if j != i else 0 for j in range(N + 1)] for i in range(N + 1)] +    MAX = int(1e9) +    link = [[MAX if i != j else 0 for j in range(N)] for i in range(N)] +        a -= 1 +        b -= 1 -    ans = MAX -    for per in list(itertools.permutations(r)): +    ans = -1 +    for t in permutations(r): -        for i in range(R - 1): -            tmp += link[per[i]][per[i + 1]] -        ans = min(ans, tmp) +        for i in range(1, R): +            tmp += link[t[i - 1] - 1][t[i] - 1] +        if ans == -1: +            ans = tmp +        else: +            ans = min(ans, tmp)