def kruskal(v_count: int, edges: list) -> int: """ :param v_count: 頂点数 :param edges: [(weight, from, to), ... ] """ from itertools import islice tree = [-1]*v_count def get_root(x) -> int: if tree[x] < 0: return x tree[x] = get_root(tree[x]) return tree[x] def unite(a) -> bool: x, y = get_root(a[1]), get_root(a[2]) if x != y: big, small = (x, y) if tree[x] < tree[y] else (y, x) tree[big] += tree[small] tree[small] = big return x != y cost = 0 for w, _s, _t in islice(filter(unite, sorted(edges)), v_count-1): cost += w return cost if __name__ == "__main__": import sys N, M, K = map(int, input().split()) edges = [[c, a-1, b-1] for _ in [0]*M for a, b, c in (map(int, sys.stdin.readline().split()),)] total = sum(v[0] for v in edges) cost = 0 for e in map(int, sys.stdin): cost += edges[e-1][0] edges[e-1][0] = 0 print(total - (kruskal(N, edges) + cost))