#include using namespace std; typedef tuple T; struct Unionfind { vector par, rank; Unionfind(int n) { par.resize(n); fill(par.begin(), par.end(), -1); rank.resize(n); fill(rank.begin(), rank.end(), 0); } int root(int x) { if (par[x]<0) return x; par[x] = root(par[x]); return par[x]; } void unite(int x, int y) { int rx = root(x), ry = root(y); if (rx==ry) return; if (rank[rx]>=rank[ry]) { par[rx] += par[ry]; par[ry] = rx; if (rank[rx]==rank[ry]) { rank[rx]++; } } else { par[ry] += par[rx]; par[rx] = ry; } } int is_same(int x, int y) { return root(x)==root(y); } int count(int x) { return -par[root(x)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; int a[M], b[M], c[M]; int cost_sum = 0; for (int i=0; i> a[i] >> b[i] >> c[i]; cost_sum += c[i]; } int flag[M]; fill(flag, flag+M, 0); for (int i=0; i> ei; flag[ei-1] = 1; } vector edges; Unionfind uf = Unionfind(N); int cost = 0; for (int i=0; i(t1)(t2);}); for (auto& [ai, bi, ci] : edges) { if (!(uf.is_same(ai, bi))) { uf.unite(ai, bi); cost += ci; } } cout << cost_sum-cost << endl; }