N,M,K=map(int,input().split()) ROAD=[list(map(int,input().split())) for i in range(M)] exc=[int(input()) for i in range(K)] S=[0 for i in range(M+1)] for e in exc: S[e]=1 SAMELIST=[i for i in range(N+1)] def find(a): while SAMELIST[a]!=a: a=SAMELIST[a] return a def Union(x,y): if find(x)!=find(y): SAMELIST[find(x)]=min(find(y),find(x)) SAMELIST[find(y)]=min(find(y),find(x)) SAMELIST[x]=min(find(y),find(x)) SAMELIST[y]=min(find(y),find(x)) for e in exc: Union(ROAD[e-1][0],ROAD[e-1][1]) from collections import defaultdict EDGE=defaultdict(int) ANS=0 for i in range(M): a,b,c=ROAD[i] if a>b: a,b=b,a if find(a)==find(b) and S[i+1]!=1: ANS+=c continue elif find(a)==find(b): continue elif EDGE[find(a),find(b)]!=0: if EDGE[find(a),find(b)]>c: ANS+=EDGE[find(a),find(b)] EDGE[find(a),find(b)]=c else: ANS+=c else: EDGE[find(a),find(b)]=c EDGE=sorted(list(EDGE.items()),key=lambda x:x[1]) from collections import deque QUE=deque(EDGE) while QUE: (a,b),cost=QUE.popleft() if find(a)==find(b): ANS+=cost else: Union(a,b) print(ANS)