Buggy python submission (verdict: Time Limit Exceeded):

def warshal_floyd(weights,N):
    d=[[weights[(i,j)] for i in range(N)] for j in range(N)]
    for i in range(N):
        d[i][i]=0
    for i in range(N):
        for j in range(N):
            for k in range(N):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d

def make_iteration(R,cities):
    S=[[c] for c in cities]
    iteration=[]
    while len(S)>0:
        v=S.pop()
        if len(v)!=len(set(v)):
            continue
        if len(v)==R:
            iteration.append(v)
        else:
            for c in cities:
                S.append(v+[c])
    return iteration

if __name__ == '__main__':
    N,M,R=list(map(int,input().split()))
    cities=list(map(int,input().split()))
    weights={(i,j):10**7 for i in range(N) for j in range(N)}
    #graph=[[10*7 for i in range(N)] for j in range(N)]
    for i in range(M):
        a,b,c=list(map(int,input().split()))
        a-=1
        b-=1
        weights[(a,b)]=min(weights[(a,b)],c)
        weights[(b,a)]=min(weights[(b,a)],c)
    d=warshal_floyd(weights,N)
    #d=floyd_warshall(weights)

    iteration=make_iteration(R,cities)
    mini_count=1e12
    for i in iteration:
        count=0
        for r in range(R-1):
            count+=d[i[r]-1][i[r+1]-1]
        mini_count=min(mini_count,count)
    print(mini_count)







Fixed submission:
from itertools import permutations
def warshal_floyd(weights,N):
    d=weights
    for i in range(N):
        d[i][i]=0
    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])
    return d

if __name__ == '__main__':
    N,M,R=list(map(int,input().split()))
    cities=[r-1 for r in list(map(int,input().split()))]
    weights=[[1e10 for i in range(N)] for j in range(N)]
    for i in range(M):
        a,b,c=list(map(int,input().split()))
        a-=1
        b-=1
        weights[a][b]=c
        weights[b][a]=c

    d=warshal_floyd(weights,N)
    mini_count=1e12
    for c in permutations(cities):
        count=sum(d[i][j] for i,j in zip(c,c[1:]))
        mini_count=min(mini_count,count)
    print(mini_count)

Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall

def warshal_floyd(weights,N):
    d=[[weights[(i,j)] for i in range(N)] for j in range(N)]
    for i in range(N):
        d[i][i]=0
    for i in range(N):
        for j in range(N):
            for k in range(N):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d

def make_iteration(R,cities):
    S=[[c] for c in cities]
    iteration=[]
    while len(S)>0:
        v=S.pop()
        if len(v)!=len(set(v)):
            continue
        if len(v)==R:
            iteration.append(v)
        else:
            for c in cities:
                S.append(v+[c])
    return iteration

if __name__ == '__main__':
    N,M,R=list(map(int,input().split()))
    cities=list(map(int,input().split()))
    weights={(i,j):10**7 for i in range(N) for j in range(N)}
    #graph=[[10*7 for i in range(N)] for j in range(N)]
    for i in range(M):
        a,b,c=list(map(int,input().split()))
        a-=1
        b-=1
        weights[(a,b)]=min(weights[(a,b)],c)
        weights[(b,a)]=min(weights[(b,a)],c)
    d=warshal_floyd(weights,N)
    #d=floyd_warshall(weights)

    iteration=make_iteration(R,cities)
    mini_count=1e12
    for i in iteration:
        count=0
        for r in range(R-1):
            count+=d[i[r]-1][i[r+1]-1]
        mini_count=min(mini_count,count)
    print(mini_count)







Fixed submission:
from itertools import permutations
def warshal_floyd(weights,N):
    d=weights
    for i in range(N):
        d[i][i]=0
    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])
    return d

if __name__ == '__main__':
    N,M,R=list(map(int,input().split()))
    cities=[r-1 for r in list(map(int,input().split()))]
    weights=[[1e10 for i in range(N)] for j in range(N)]
    for i in range(M):
        a,b,c=list(map(int,input().split()))
        a-=1
        b-=1
        weights[a][b]=c
        weights[b][a]=c

    d=warshal_floyd(weights,N)
    mini_count=1e12
    for c in permutations(cities):
        count=sum(d[i][j] for i,j in zip(c,c[1:]))
        mini_count=min(mini_count,count)
    print(mini_count)