class Unionfind: def __init__(self, num): self.num = num self.parents = [-1for _ in range(num)] def find(self, x): if self.parents[x] < 0: 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 x == y: return if self.find(x) > self.find(y): x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def main(): n, m, k = map(int, input().split()) e = [list(map(int, input().split()))for _ in range(m)] ban = set([int(input())-1 for _ in range(k)]) uf = Unionfind(n) ans = 0 s = [] for i, x in enumerate(e): u, v, w = x if i in ban: uf.union(u-1, v-1) else: s.append((w, u-1, v-1)) s.sort() for w, u, v, in s: if uf.same(u, v): ans += w else: uf.union(u, v) print(ans) if __name__ == "__main__": main()