N, M, K = map(int, input().split()) citys = {n: {'Root': n, 'child': {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] # print(a, b) if citys[a]['Root'] == a and citys[b]['Root'] == b: for c in citys[citys[b]['Root']]['child']: citys[c]['Root'] = a citys[a]['child'].add(c) elif citys[a]['Root'] == a and citys[b]['Root'] != b: for c in citys[citys[b]['Root']]['child']: citys[c]['Root'] = citys[a]['Root'] citys[citys[a]['Root']]['child'].add(c) else: for c in citys[citys[a]['Root']]['child']: citys[c]['Root'] = citys[b]['Root'] citys[citys[b]['Root']]['child'].add(c) del_weight = 0 for ix, e in enumerate(sorted_edges): # edge eを追加できるかどうか a, b, c = edges[e] # print(ix+1, a, b, c) if citys[a]['Root'] == citys[b]['Root']: del_weight += c continue if citys[a]['Root'] == a and citys[b]['Root'] == b: for c in citys[citys[b]['Root']]['child']: citys[c]['Root'] = a citys[a]['child'].add(c) else: for c in citys[citys[b]['Root']]['child']: citys[c]['Root'] = citys[a]['Root'] citys[citys[a]['Root']]['child'].add(c) print(del_weight)