from itertools import permutations

import sys

import gc

def main():

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

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

    # グラフを作る

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

    for e in sys.stdin:

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

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

    # ワーシャルフロイドで全頂点間距離算出

    for k in range(N):

        for i in range(N):

            for j in range(N):

                if dist[i][j] > dist[i][k] + dist[k][j]:

                    dist[i][j] = dist[i][k] + dist[k][j]

    # 組み合わせ全探索

    ans = float('inf')

    for p in permutations(rs):

        tmp = 0

        for u, v in zip(p, p[1:]):

            tmp += dist[u][v]

            if tmp > ans:

                break

        else:

            ans = tmp

    print(ans)

if __name__ == '__main__':

    gc.disable()

    main()
from itertools import permutations

import sys

def main():

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

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

    # グラフを作る

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

    for e in sys.stdin:

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

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

    # ワーシャルフロイドで全頂点間距離算出

    for k in range(N):

        for i in range(N):

            for j in range(N):

                if dist[i][j] > dist[i][k] + dist[k][j]:

                    dist[i][j] = dist[i][k] + dist[k][j]

    # 組み合わせ全探索

    ans = float('inf')

    for p in permutations(rs):

        ans = min(ans, sum(dist[u][v] for u, v in zip(p, p[1:])))

    print(ans)

if __name__ == '__main__':

    main()
from itertools import permutations
import sys
import gc


def main():
    N, M, R = list(map(int, input().split()))
    rs = [x - 1 for x in map(int, input().split())]
    # グラフを作る
    dist = [[float("inf")] * (N) for _ in range(N)]
    for e in sys.stdin:
        A, B, C = list(map(int, e.split()))
        dist[A - 1][B - 1] = dist[B - 1][A - 1] = C
    # ワーシャルフロイドで全頂点間距離算出
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    # 組み合わせ全探索
    ans = float("inf")
    for p in permutations(rs):
        tmp = 0
        for u, v in zip(p, p[1:]):
            tmp += dist[u][v]
            if tmp > ans:
                break
        else:
            ans = tmp
    print(ans)


if __name__ == "__main__":
    gc.disable()
    main()

from itertools import permutations
import sys


def main():
    N, M, R = list(map(int, input().split()))
    rs = [x - 1 for x in map(int, input().split())]
    # グラフを作る
    dist = [[float("inf")] * (N) for _ in range(N)]
    for e in sys.stdin:
        A, B, C = list(map(int, e.split()))
        dist[A - 1][B - 1] = dist[B - 1][A - 1] = C
    # ワーシャルフロイドで全頂点間距離算出
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    # 組み合わせ全探索
    ans = float("inf")
    for p in permutations(rs):
        ans = min(ans, sum(dist[u][v] for u, v in zip(p, p[1:])))
    print(ans)


if __name__ == "__main__":
    main()

-import gc -        tmp = 0 -        for u, v in zip(p, p[1:]): -            tmp += dist[u][v] -            if tmp > ans: -                break -        else: -            ans = tmp +        ans = min(ans, sum(dist[u][v] for u, v in zip(p, p[1:]))) -    gc.disable()