int main() { UnionFindSet *u = new UnionFindSet(8); cout << "Original" << endl; u->Display(); u->Union(0, 1); u->Union(1, 2); u->Union(3, 4); u->Union(4, 5); u->Union(0, 4); u->Union(6, 7); cout << endl; cout << "After Union" << endl; u->Display(); delete u; }
void solve() { UnionFindSet ufs = UnionFindSet(N); int ans = 0; sort(edges.begin(), edges.end()); for (int i = 0; i < M; i ++) { if (ufs.setCnt <= K) break; if (ufs.Union(edges[i].a - 1, edges[i].b - 1)) ans += edges[i].c; } if (ufs.setCnt <= K) { cout << ans << endl; } else { cout << "Impossible!" << endl; } }