N, M, K = map(int, input().split()) Root = [n for n in range(N)] Root_num = [1 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} del_weight = 0 def get_Root(c): if Root[c] == c: return c else: return get_Root(Root[c]) def merge(a, b): root_a = get_Root(a) root_b = get_Root(b) if Root_num[root_a] < Root_num[root_b]: Root[root_a] = Root[root_b] Root_num[root_b] += Root_num[root_a] else: Root[root_b] = Root[root_a] Root_num[root_a] += Root_num[root_b] # union tree for e in abs_edges: a, b, c = edges[e] merge(a, b) for e in sorted_edges: # edge eを追加できるかどうか a, b, c = edges[e] if get_Root(a) == get_Root(b): del_weight += c continue merge(a, b) print(del_weight)