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

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

#dp[i][j][k] -> 町iまで経由地点として使える。j,kの最短移動距離

dp = [[float("INF")]*(N+1) for _ in range(N+1)]

for _ in range(M):

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

    dp[a][b] = c

    dp[b][a] = c



for i in range(N+1):

    dp[i][i] = 0



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

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

        for k in range(N+1):

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



from itertools import permutations

ans = float("INF")

for pattern in permutations(R):

    cost = 0

    for i in range(r-1):

        cost += dp[pattern[i]][pattern[i+1]]

    ans = min(ans,cost)

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

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

dp = [[float("INF")]*(N+1) for _ in range(N+1)]

for i in range(N+1):

    dp[i][i] = 0



for _ in range(M):

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

    dp[a][b] = c

    dp[b][a] = c



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

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

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

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



candidate = []

def dfs (r,cost,path=set()):

    path.add(r)

    if len(path) == len(R):

        candidate.append(cost)

    else:

        for nx in R:

            if nx not in path:

                dfs(nx,cost+dp[r][nx],path)

    path.remove(r)



for r in R:

    dfs(r,0)

print((min(candidate)))



N, M, r = list(map(int, input().split()))
R = list(map(int, input().split()))
# dp[i][j][k] -> 町iまで経由地点として使える。j,kの最短移動距離
dp = [[float("INF")] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    dp[a][b] = c
    dp[b][a] = c
for i in range(N + 1):
    dp[i][i] = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        for k in range(N + 1):
            dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k])
from itertools import permutations

ans = float("INF")
for pattern in permutations(R):
    cost = 0
    for i in range(r - 1):
        cost += dp[pattern[i]][pattern[i + 1]]
    ans = min(ans, cost)
print(ans)

N, M, R = list(map(int, input().split()))
R = list(map(int, input().split()))
dp = [[float("INF")] * (N + 1) for _ in range(N + 1)]
for i in range(N + 1):
    dp[i][i] = 0
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    dp[a][b] = c
    dp[b][a] = c
for i in range(1, N + 1):
    for j in range(1, N + 1):
        for k in range(1, N + 1):
            dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k])
candidate = []


def dfs(r, cost, path=set()):
    path.add(r)
    if len(path) == len(R):
        candidate.append(cost)
    else:
        for nx in R:
            if nx not in path:
                dfs(nx, cost + dp[r][nx], path)
    path.remove(r)


for r in R:
    dfs(r, 0)
print((min(candidate)))

-N, M, r = list(map(int, input().split())) +N, M, R = list(map(int, input().split())) -# dp[i][j][k] -> 町iまで経由地点として使える。j,kの最短移動距離 +for i in range(N + 1): +    dp[i][i] = 0 -for i in range(N + 1): -    dp[i][i] = 0 -        for k in range(N + 1): +        for k in range(1, N + 1): -from itertools import permutations +candidate = [] -ans = float("INF") -for pattern in permutations(R): -    cost = 0 -    for i in range(r - 1): -        cost += dp[pattern[i]][pattern[i + 1]] -    ans = min(ans, cost) -print(ans) + +def dfs(r, cost, path=set()): +    path.add(r) +    if len(path) == len(R): +        candidate.append(cost) +    else: +        for nx in R: +            if nx not in path: +                dfs(nx, cost + dp[r][nx], path) +    path.remove(r) + + +for r in R: +    dfs(r, 0) +print((min(candidate)))