import itertools



def warshall_floyd(D, n):

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





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

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

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

for i in range(N):

    D[i][i] = 0

for _ in range(M):

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

    D[a-1][b-1] = c

    D[b-1][a-1] = c



warshall_floyd(D, N)



ans = float('inf')

for P in itertools.permutations(r):

    cost = 0

    for i in range(R-1):

        cost += D[P[i]-1][P[i+1]-1]

    ans = min(ans, cost)



print(ans)
import itertools

import sys

input = sys.stdin.readline



def warshall_floyd(D, n):

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



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 i in range(N):

        D[i][i] = 0

    for _ in range(M):

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

        D[a-1][b-1] = c

        D[b-1][a-1] = c



    warshall_floyd(D, N)



    ans = float('inf')

    for P in itertools.permutations(r):

        cost = 0

        for i in range(R-1):

            cost += D[P[i]-1][P[i+1]-1]

        ans = min(ans, cost)



    print(ans)





if __name__ == '__main__':

    main()
import itertools


def warshall_floyd(D, n):
    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])


N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
D = [[float("inf")] * N for _ in range(N)]
for i in range(N):
    D[i][i] = 0
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    D[a - 1][b - 1] = c
    D[b - 1][a - 1] = c
warshall_floyd(D, N)
ans = float("inf")
for P in itertools.permutations(r):
    cost = 0
    for i in range(R - 1):
        cost += D[P[i] - 1][P[i + 1] - 1]
    ans = min(ans, cost)
print(ans)

import itertools
import sys

input = sys.stdin.readline


def warshall_floyd(D, n):
    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])


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 i in range(N):
        D[i][i] = 0
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        D[a - 1][b - 1] = c
        D[b - 1][a - 1] = c
    warshall_floyd(D, N)
    ans = float("inf")
    for P in itertools.permutations(r):
        cost = 0
        for i in range(R - 1):
            cost += D[P[i] - 1][P[i + 1] - 1]
        ans = min(ans, cost)
    print(ans)


if __name__ == "__main__":
    main()

+import sys + +input = sys.stdin.readline -N, M, R = list(map(int, input().split())) -r = list(map(int, input().split())) -D = [[float("inf")] * N for _ in range(N)] -for i in range(N): -    D[i][i] = 0 -for _ in range(M): -    a, b, c = list(map(int, input().split())) -    D[a - 1][b - 1] = c -    D[b - 1][a - 1] = c -warshall_floyd(D, N) -ans = float("inf") -for P in itertools.permutations(r): -    cost = 0 -    for i in range(R - 1): -        cost += D[P[i] - 1][P[i + 1] - 1] -    ans = min(ans, cost) -print(ans) +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 i in range(N): +        D[i][i] = 0 +    for _ in range(M): +        a, b, c = list(map(int, input().split())) +        D[a - 1][b - 1] = c +        D[b - 1][a - 1] = c +    warshall_floyd(D, N) +    ans = float("inf") +    for P in itertools.permutations(r): +        cost = 0 +        for i in range(R - 1): +            cost += D[P[i] - 1][P[i + 1] - 1] +        ans = min(ans, cost) +    print(ans) + + +if __name__ == "__main__": +    main()