#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from operator import itemgetter # %% N, M, K = map(int, readline().split()) data = list(map(int, read().split())) A = data[: 3 * M:3] B = data[1: 3 * M:3] C = data[2: 3 * M:3] E = data[3 * M:] E = [e - 1 for e in E] # %% class UnionFind: def __init__(self, N): self.root = list(range(N)) self.size = [1] * (N) def find_root(self, x): root = self.root while root[x] != x: root[x] = root[root[x]] x = root[x] return x def merge(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return False sx, sy = self.size[x], self.size[y] if sx < sy: self.root[x] = y self.size[y] += sx else: self.root[y] = x self.size[x] += sy return True # %% uf = UnionFind(N + 1) merge = uf.merge for i in E: a, b, c = A[i], B[i], C[i] merge(a, b) seE = set(E) restA = [x for i, x in enumerate(A) if i not in seE] restB = [x for i, x in enumerate(B) if i not in seE] restC = [x for i, x in enumerate(C) if i not in seE] # %% answer = 0 restABC = sorted(zip(restA, restB, restC), key=itemgetter(2)) for a, b, c in restABC: if not merge(a, b): answer += c print(answer)