from itertools import permutations

from heapq import *



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

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

INF=float("inf")

G=[[INF]*N for i in range(N)]

for i in range(M):

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

    A,B=A-1,B-1

    G[A][B]=C

    G[B][A]=C

def distance(a,b):

    stack=[(G[a][i],i) for i in range(N) if G[a][i]!=INF]

    heapify(stack)

    reached=[0]*N

    reached[0]=1

    dis=[INF]*N

    dis[0]=0

    while(stack):

        c,i=heappop(stack)

        if reached[i]==1:

            continue

        if dis[i]<=c:

            continue

        dis[i]=c

        if i==b:

            return c

        reached[i]=1

        for j in range(N):

            if G[i][j]!=INF and reached[j]==0:

                heappush(stack,(G[i][j]+dis[i],j))

D=[[0]*N for i in range(N)]

for i in r:

    for j in r:

        if i>=j:

            continue

        D[i-1][j-1]=distance(i-1,j-1)

        D[j-1][i-1]=D[i-1][j-1]

ans=10**9

for r_ in permutations(r):

    res=0

    for i in range(R-1):

        res+=D[r_[i]-1][r_[i+1]-1]

    ans=min(ans,res)

print(ans)

from itertools import permutations

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

INF=10**9

d=[[INF]*N for i in range(N)]

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

for i in range(M):

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

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

  d[B-1][A-1]=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=10**9

for L in permutations(r):

  temp=0

  for j in range(R-1):

    temp+=d[L[j]-1][L[j+1]-1]

  ans=min(temp,ans)

print(ans)

from itertools import permutations
from heapq import *

N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
INF = float("inf")
G = [[INF] * N for i in range(N)]
for i in range(M):
    A, B, C = list(map(int, input().split()))
    A, B = A - 1, B - 1
    G[A][B] = C
    G[B][A] = C


def distance(a, b):
    stack = [(G[a][i], i) for i in range(N) if G[a][i] != INF]
    heapify(stack)
    reached = [0] * N
    reached[0] = 1
    dis = [INF] * N
    dis[0] = 0
    while stack:
        c, i = heappop(stack)
        if reached[i] == 1:
            continue
        if dis[i] <= c:
            continue
        dis[i] = c
        if i == b:
            return c
        reached[i] = 1
        for j in range(N):
            if G[i][j] != INF and reached[j] == 0:
                heappush(stack, (G[i][j] + dis[i], j))


D = [[0] * N for i in range(N)]
for i in r:
    for j in r:
        if i >= j:
            continue
        D[i - 1][j - 1] = distance(i - 1, j - 1)
        D[j - 1][i - 1] = D[i - 1][j - 1]
ans = 10**9
for r_ in permutations(r):
    res = 0
    for i in range(R - 1):
        res += D[r_[i] - 1][r_[i + 1] - 1]
    ans = min(ans, res)
print(ans)

from itertools import permutations

N, M, R = list(map(int, input().split()))
INF = 10**9
d = [[INF] * N for i in range(N)]
r = list(map(int, input().split()))
for i in range(M):
    A, B, C = list(map(int, input().split()))
    d[A - 1][B - 1] = C
    d[B - 1][A - 1] = 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 = 10**9
for L in permutations(r):
    temp = 0
    for j in range(R - 1):
        temp += d[L[j] - 1][L[j + 1] - 1]
    ans = min(temp, ans)
print(ans)

-from heapq import * +INF = 10**9 +d = [[INF] * N for i in range(N)] -INF = float("inf") -G = [[INF] * N for i in range(N)] -    A, B = A - 1, B - 1 -    G[A][B] = C -    G[B][A] = C - - -def distance(a, b): -    stack = [(G[a][i], i) for i in range(N) if G[a][i] != INF] -    heapify(stack) -    reached = [0] * N -    reached[0] = 1 -    dis = [INF] * N -    dis[0] = 0 -    while stack: -        c, i = heappop(stack) -        if reached[i] == 1: -            continue -        if dis[i] <= c: -            continue -        dis[i] = c -        if i == b: -            return c -        reached[i] = 1 +    d[A - 1][B - 1] = C +    d[B - 1][A - 1] = C +for k in range(N): +    for i in range(N): -            if G[i][j] != INF and reached[j] == 0: -                heappush(stack, (G[i][j] + dis[i], j)) - - -D = [[0] * N for i in range(N)] -for i in r: -    for j in r: -        if i >= j: -            continue -        D[i - 1][j - 1] = distance(i - 1, j - 1) -        D[j - 1][i - 1] = D[i - 1][j - 1] +            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) -for r_ in permutations(r): -    res = 0 -    for i in range(R - 1): -        res += D[r_[i] - 1][r_[i + 1] - 1] -    ans = min(ans, res) +for L in permutations(r): +    temp = 0 +    for j in range(R - 1): +        temp += d[L[j] - 1][L[j + 1] - 1] +    ans = min(temp, ans)