import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) class UnionFind: def __init__(self, N): self.par = [i for i in range(N)] self.rank = [0] * N 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 same_check(self, x, y): return self.find(x) == self.find(y) def union(self, x, y): x = self.find(x); y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 class Kruskal: def __init__(self, E, N, M, UF, cost): self.uf = UF self.cost = cost for w, u, v, itr in E: if self.uf.same_check(u, v) != True: self.uf.union(u, v) self.cost += w def mincost(self): return self.cost #処理内容 def main(): N, M, K = getlist() E = [] totalcost = 0 for i in range(M): a, b, c = getlist() a -= 1; b -= 1 totalcost += c E.append((c, a, b, i)) UF = UnionFind(N) cost = 0 for i in range(K): e = int(input()) e -= 1 c, a, b, itr = E[e] UF.union(a, b) cost += c E.sort(key = lambda x:x[0]) K = Kruskal(E, N, M, UF, cost) finalcost = K.mincost() print(totalcost - finalcost) if __name__ == '__main__': main()