from itertools import permutations



def main():

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

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

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

    for _ in range(M):

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

        A -= 1

        B -= 1

        d[A][B] = C

        d[B][A] = C

    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])



    ans = float('inf')

    for D in list(permutations(r)):

        tmp = 0

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

            tmp += d[D[i]-1][D[i+1]-1]

        ans = min(ans, tmp)



    print(ans)







           







if __name__ == "__main__":

    main()
from itertools import permutations



def main():

    N: int

    M: int

    R: int

    A: int

    B: int

    C: int

    ans: int    

    INF: int

    INF = 10 ** 10

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

    r: list = list([x - 1 for x in list(map(int, input().split()))])

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

    for _ in range(M):

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

        A -= 1

        B -= 1

        dist[A][B] = C

        dist[B][A] = C

    for i in range(N):

        dist[i][i] = 0

    

    for k in range(N):

        for i in range(N):

            for j in range(N):

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

    ans = INF

    for item in permutations(r):

        L: int = len(item)

        d: int = 0

        for i in range(1,L):

            pre: int = item[i-1]

            now: int = item[i]

            d += dist[pre][now]

        ans = min(ans, d)

    print(ans)  



if __name__ == "__main__":

    main()
from itertools import permutations


def main():
    N, M, R = list(map(int, input().split()))
    r = list(map(int, input().split()))
    d = [[float("inf")] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = list(map(int, input().split()))
        A -= 1
        B -= 1
        d[A][B] = C
        d[B][A] = C
    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])
    ans = float("inf")
    for D in list(permutations(r)):
        tmp = 0
        for i in range(len(D) - 1):
            tmp += d[D[i] - 1][D[i + 1] - 1]
        ans = min(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

from itertools import permutations


def main():
    N: int
    M: int
    R: int
    A: int
    B: int
    C: int
    ans: int
    INF: int
    INF = 10**10
    N, M, R = list(map(int, input().split()))
    r: list = list([x - 1 for x in list(map(int, input().split()))])
    dist: list = [[float("inf")] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = list(map(int, input().split()))
        A -= 1
        B -= 1
        dist[A][B] = C
        dist[B][A] = C
    for i in range(N):
        dist[i][i] = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    ans = INF
    for item in permutations(r):
        L: int = len(item)
        d: int = 0
        for i in range(1, L):
            pre: int = item[i - 1]
            now: int = item[i]
            d += dist[pre][now]
        ans = min(ans, d)
    print(ans)


if __name__ == "__main__":
    main()

+    N: int +    M: int +    R: int +    A: int +    B: int +    C: int +    ans: int +    INF: int +    INF = 10**10 -    r = list(map(int, input().split())) -    d = [[float("inf")] * N for _ in range(N)] +    r: list = list([x - 1 for x in list(map(int, input().split()))]) +    dist: list = [[float("inf")] * N for _ in range(N)] -        d[A][B] = C -        d[B][A] = C +        dist[A][B] = C +        dist[B][A] = C +    for i in range(N): +        dist[i][i] = 0 -                d[i][j] = min(d[i][j], d[i][k] + d[k][j]) -    ans = float("inf") -    for D in list(permutations(r)): -        tmp = 0 -        for i in range(len(D) - 1): -            tmp += d[D[i] - 1][D[i + 1] - 1] -        ans = min(ans, tmp) +                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) +    ans = INF +    for item in permutations(r): +        L: int = len(item) +        d: int = 0 +        for i in range(1, L): +            pre: int = item[i - 1] +            now: int = item[i] +            d += dist[pre][now] +        ans = min(ans, d)