#include #include #include using namespace std; struct UnionFind { vector data; int __size; UnionFind(int size) : data(size, -1), __size(size) { } bool unionSet(int x, int y) { if ((x = root(x)) != (y = root(y))) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; __size--; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } int size() { return __size; } }; template struct Edge { int src, dst; T cost; Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { } Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { } }; template using Edges = vector>; template pair> kruskal(Edges &edges, Edges &fixed, int v) { sort(begin(edges), end(edges), [](const Edge &a, const Edge &b) { return a.cost < b.cost; }); UnionFind uf(v); T total = 0; Edges F; for (auto &e: fixed) { uf.unionSet(e.src, e.dst), total += e.cost, F.emplace_back(e); } for (auto &e: edges) { if (uf.unionSet(e.src, e.dst)) total += e.cost, F.emplace_back(e); } return {total, F}; } int main() { int V, E, K; cin >> V >> E >> K; Edges edges, fixed; long long sum = 0; while (E--) { int s, t, w; cin >> s >> t >> w; s--, t--; edges.emplace_back(s, t, w); sum += w; } while (K--) { int e; cin >> e; e--; fixed.emplace_back(edges[e]); } cout << sum - kruskal(edges, fixed, V).first << endl; return 0; }