def warshall_floyd(paths, N):

    for k in range(N):

        for i in range(N):

            for j in range(N):

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





def iter_patterns(l):

    if len(l) == 1:

        return [l]

    patterns = []

    for i in range(len(l)):

        patterns += [[l[i]] + p for p in iter_patterns(l[:i] + l[i+1:])]

    return patterns





def main():

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

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

    paths = [[float("inf")] * N for _ in range(N)]

    for _ in range(M):

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

        paths[A-1][B-1] = C

        paths[B-1][A-1] = C

    for i in range(N):

        paths[i][i] = 0

    warshall_floyd(paths, N)

    retval = float("inf")

    for p in iter_patterns(r):

        dist = 0

        for i in range(R-1):

            dist += paths[p[i]-1][p[i+1]-1]

        retval = min(retval, dist)

    print(retval)





if __name__ == "__main__":

    main()

import itertools



INF = float("inf")





def main():

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

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

    path = [[INF]*(N+1) for _ in range(N+1)]

    for _ in range(M):

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

        path[A][B] = C

        path[B][A] = C

    for i in range(1, N+1):

        path[i][i] = 0

    for i in range(1, N+1):

        for j in range(1, N+1):

            for k in range(1, N+1):

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

    ans = INF

    for p in itertools.permutations(r):

        cost = 0

        for i in range(R-1):

            cost += path[p[i]][p[i+1]]

        ans = min(ans, cost)

    print(ans)





if __name__ == "__main__":

    main()

def warshall_floyd(paths, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                paths[i][j] = min(paths[i][j], paths[i][k] + paths[k][j])


def iter_patterns(l):
    if len(l) == 1:
        return [l]
    patterns = []
    for i in range(len(l)):
        patterns += [[l[i]] + p for p in iter_patterns(l[:i] + l[i + 1 :])]
    return patterns


def main():
    N, M, R = list(map(int, input().split()))
    r = list(map(int, input().split()))
    paths = [[float("inf")] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = list(map(int, input().split()))
        paths[A - 1][B - 1] = C
        paths[B - 1][A - 1] = C
    for i in range(N):
        paths[i][i] = 0
    warshall_floyd(paths, N)
    retval = float("inf")
    for p in iter_patterns(r):
        dist = 0
        for i in range(R - 1):
            dist += paths[p[i] - 1][p[i + 1] - 1]
        retval = min(retval, dist)
    print(retval)


if __name__ == "__main__":
    main()

import itertools

INF = float("inf")


def main():
    N, M, R = list(map(int, input().split()))
    r = list(map(int, input().split()))
    path = [[INF] * (N + 1) for _ in range(N + 1)]
    for _ in range(M):
        A, B, C = list(map(int, input().split()))
        path[A][B] = C
        path[B][A] = C
    for i in range(1, N + 1):
        path[i][i] = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            for k in range(1, N + 1):
                path[j][k] = min(path[j][k], path[j][i] + path[i][k])
    ans = INF
    for p in itertools.permutations(r):
        cost = 0
        for i in range(R - 1):
            cost += path[p[i]][p[i + 1]]
        ans = min(ans, cost)
    print(ans)


if __name__ == "__main__":
    main()

-def warshall_floyd(paths, N): -    for k in range(N): -        for i in range(N): -            for j in range(N): -                paths[i][j] = min(paths[i][j], paths[i][k] + paths[k][j]) +import itertools - -def iter_patterns(l): -    if len(l) == 1: -        return [l] -    patterns = [] -    for i in range(len(l)): -        patterns += [[l[i]] + p for p in iter_patterns(l[:i] + l[i + 1 :])] -    return patterns +INF = float("inf") -    paths = [[float("inf")] * N for _ in range(N)] +    path = [[INF] * (N + 1) for _ in range(N + 1)] -        paths[A - 1][B - 1] = C -        paths[B - 1][A - 1] = C -    for i in range(N): -        paths[i][i] = 0 -    warshall_floyd(paths, N) -    retval = float("inf") -    for p in iter_patterns(r): -        dist = 0 +        path[A][B] = C +        path[B][A] = C +    for i in range(1, N + 1): +        path[i][i] = 0 +    for i in range(1, N + 1): +        for j in range(1, N + 1): +            for k in range(1, N + 1): +                path[j][k] = min(path[j][k], path[j][i] + path[i][k]) +    ans = INF +    for p in itertools.permutations(r): +        cost = 0 -            dist += paths[p[i] - 1][p[i + 1] - 1] -        retval = min(retval, dist) -    print(retval) +            cost += path[p[i]][p[i + 1]] +        ans = min(ans, cost) +    print(ans)