#unionfind経路圧縮あり import collections class UnionFind(): def __init__(self, n): self.n = n self.parents = list(range(n)) self.size0 = [1]*(n) self.roots = n def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if self.parents[x] > self.parents[y]: x, y = y, x if x == y: return self.size0[x] += self.size0[y] self.roots -= 1 self.parents[y] = x def size(self, x):#O(1)xが含まれる集合の要素数 return self.size0[self.find(x)] def same(self, x, y):#O(1) return self.find(x) == self.find(y) def membersf(self, x):#取り出し部分はO(N) p = self.find(x) ret = [] for i in range(self.n): if self.find(i) == p: ret.append(i) return ret def rootsf(self):#根の要素O(N) ret = [] for i in range(self.n): if self.find(i) == i: ret.append(i) return ret def group_count(self):#根の数O(1) return self.roots def all_group_members(self):#O(N) ret = collections.defaultdict(lambda:[]) for i in range(self.n): ret[self.find(i)].append(i) return ret import heapq N,M,K = map(int,input().split()) lsn = [] for i in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 lsn.append((c,a,b)) lsn2 = [True]*M UF = UnionFind(N) for i in range(K): e = int(input())-1 lsn2[e] = False UF.union(lsn[e][1], lsn[e][2]) lsn3 = [] for i in range(M): if lsn2[i]: lsn3.append(lsn[i]) ans = 0 heapq.heapify(lsn3) while lsn3: c,a,b = heapq.heappop(lsn3) if UF.same(a, b): ans += c else: UF.union(a, b) print(ans)