N, M, K = map(int, input().split()) Root = [n for n in range(N)] Children = [{n} for n in range(N)] edges = [None for _ in range(M)] for m in range(M): a, b, c = map(int, input().split()) edges[m] = (a-1, b-1, c) abs_edges = set(int(input())-1 for _ in range(K)) sorted_edges = sorted([e for e in set(range(M)) - abs_edges], key=lambda x: edges[x][2]) # 最小木 T = {edges[e] for e in abs_edges} # union tree for e in abs_edges: a, b, _ = edges[e] if Root[a] == a and Root[b] == b: for c in Children[Root[b]]: Root[c] = a Children[a].add(c) elif Root[a] == a and Root[b] != b: for c in Children[Root[b]]: Root[c] = Root[a] Children[Root[a]].add(c) else: for c in Children[Root[a]]: Root[c] = Root[b] Children[Root[b]].add(c) del_weight = 0 for ix, e in enumerate(sorted_edges): # edge eを追加できるかどうか a, b, c = edges[e] if Root[a] == Root[b]: del_weight += c continue if Root[a] == a and Root[b] == b: for c in Children[Root[b]]: Root[c] = a Children[a].add(c) elif Root[a] == a and Root[b] != b: for c in Children[Root[b]]: Root[c] = Root[a] Children[Root[a]].add(c) else: for c in Children[Root[a]]: Root[c] = Root[b] Children[Root[b]].add(c) print(del_weight)