N,M,K=[int(i) for i in input().split()] e=[];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={}; pn=0 l=[-1 for _ in range(N+1)] for j in range(K): i=int(input())-1 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] if l[a]<0 and l[b]<0: p[pn]={a,b}; l[a]=pn; l[b]=pn; pn+=1 elif l[a]<0: p[l[b]].add(a); l[a]=l[b] elif l[b]<0: p[l[a]].add(b); l[b]=l[a] elif l[a]!=l[b]: t=l[b] p[l[a]]|=p[t] for i in p[t]: l[i]=l[a] del p[t] 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] if l[a]<0 and l[b]<0: p[pn]={a,b}; l[a]=pn; l[b]=pn; pn+=1 elif l[a]<0: p[l[b]].add(a); l[a]=l[b] elif l[b]<0: p[l[a]].add(b); l[b]=l[a] elif l[a]!=l[b]: t=l[b] p[l[a]]|=p[t] for i in p[t]: l[i]=l[a] del p[t] else: continue s-=f[0] print(s)