import sys def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]); ptr += 1 M = int(input[ptr]); ptr += 1 K = int(input[ptr]); ptr += 1 edges = [] total_cost = 0 for _ in range(M): a = int(input[ptr]) - 1; ptr += 1 b = int(input[ptr]) - 1; ptr += 1 c = int(input[ptr]); ptr += 1 edges.append((a, b, c)) total_cost += c specified = set() for _ in range(K): e = int(input[ptr]) - 1; ptr += 1 specified.add(e) # Union-Find setup parent = list(range(N)) rank = [1] * N def find(u): while parent[u] != u: parent[u] = parent[parent[u]] u = parent[u] return u def union(u, v): u_root = find(u) v_root = find(v) if u_root == v_root: return False if rank[u_root] < rank[v_root]: parent[u_root] = v_root else: parent[v_root] = u_root if rank[u_root] == rank[v_root]: rank[u_root] += 1 return True sum_kept = 0 # Process specified edges for e_idx in specified: a, b, c = edges[e_idx] sum_kept += c # Perform union without checking, to build the connected components union(a, b) # Collect remaining edges remaining = [] for i in range(M): if i not in specified: a, b, c = edges[i] remaining.append((c, a, b)) # Sort by cost ascending remaining.sort() # Process remaining edges in Kruskal's manner for c, a, b in remaining: if find(a) != find(b): if union(a, b): sum_kept += c # The result is total_cost minus the sum of kept edges print(total_cost - sum_kept) if __name__ == "__main__": main()