class UnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) self.size = [1 for _ in range(n+1)] # 検索 def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] # 併合 def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y self.size[y] += self.size[x] else: self.par[y] = x self.size[x] += self.size[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 # 同じ集合に属するか判定 def same_check(self, x, y): return self.find(x) == self.find(y) n,m,k = map(int,input().split()) li = [] ab = [[] for i in range(n)] for i in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 li.append([a,b,c,i]) #ab[a].append([b,c]) #[b].append([a,c]) e = [int(input())-1 for i in range(k)] ki = UnionFind(n+1) for i in range(k): a,b,c,idx = li[e[i]] ki.union(a,b) e = set(e) li.sort(key=lambda x:(x[2])) #print(li) ans = 0 for i in range(m): if li[i][3] in e: continue a,b,c,idx = li[i] if not ki.same_check(a,b): ki.union(a,b) else: ans += c #print(i,ans) print(ans)