N,M,K=[int(i) for i in input().split()] e=[];t=set();s=0 for j in range(M): a,b,c=[int(i) for i in input().split()] e.append((c,a,b)) s+=c o=sorted(e) p=[] for j in range(K): i=int(input())-1 t.add(i) a,b=e[i][1:3] x=-1;y=-1 for k,q in enumerate(p): if a in q: x=k if b in q: y=k if x<0 and y<0: p.append({a,b}) elif x<0: p[y].add(a) elif y<0: p[x].add(b) elif x!=y: p[x]|=p[y]; del p[y] s-=e[i][0] for f in o: a,b=f[1:3] x=-1;y=-1 for k,q in enumerate(p): if a in q: x=k if b in q: y=k if x<0 and y<0: p.append({a,b}) elif x<0: p[y].add(a) elif y<0: p[x].add(b) elif x!=y: p[x]|=p[y]; del p[y] else: continue s-=f[0] print(s)