CMakeLists.txt

This commit is contained in:
2026-07-31 00:33:17 +08:00
parent f853068f9b
commit 32d7529967
8 changed files with 396 additions and 71 deletions
@@ -34,5 +34,20 @@ int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
size_t students_count, pairs_count;
for (int case_id = 1; cin >> students_count >> pairs_count && students_count; case_id++) {
cout << "Case " << case_id << ": ";
Dsu dsu(students_count);
size_t x, y, ans = 0;
for (int _ = 0; _ < pairs_count; _++) {
cin >> x >> y;
dsu.unite(x - 1, y - 1);
}
for (size_t node_id = 0; node_id < students_count; node_id++) {
ans += node_id == dsu.find(node_id);
}
cout << ans << endl;
}
return 0;
}