CMakeLists.txt
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user