結果
問題 | No.2418 情報通だよ!Nafmoくん |
ユーザー | rinrion |
提出日時 | 2023-08-12 14:46:46 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,294 bytes |
コンパイル時間 | 3,439 ms |
コンパイル使用メモリ | 230,684 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-30 07:10:25 |
合計ジャッジ時間 | 5,226 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 51 ms
6,940 KB |
testcase_04 | AC | 7 ms
6,940 KB |
testcase_05 | AC | 35 ms
6,940 KB |
testcase_06 | AC | 33 ms
6,940 KB |
testcase_07 | AC | 40 ms
6,940 KB |
testcase_08 | AC | 33 ms
6,940 KB |
testcase_09 | AC | 47 ms
6,940 KB |
testcase_10 | AC | 52 ms
6,944 KB |
testcase_11 | AC | 45 ms
6,944 KB |
testcase_12 | AC | 29 ms
6,944 KB |
testcase_13 | AC | 15 ms
6,940 KB |
testcase_14 | AC | 27 ms
6,944 KB |
testcase_15 | AC | 36 ms
6,940 KB |
testcase_16 | AC | 54 ms
6,944 KB |
testcase_17 | AC | 18 ms
6,944 KB |
testcase_18 | AC | 26 ms
6,940 KB |
testcase_19 | AC | 5 ms
6,944 KB |
testcase_20 | AC | 37 ms
6,944 KB |
testcase_21 | AC | 17 ms
6,940 KB |
testcase_22 | AC | 21 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; // 宣言 unionfind 変数名(頂点数) 各関数を利用 変数名.unite(x, y) struct unionfind{ //par=親 siz=グループの頂点数 vector<int>par, siz; unionfind(int n) : par(n, -1),siz(n, 1){} //根を求める int root(int x){ if(par[x] == -1) return x; else return par[x] = root(par[x]); } //xとyが同グループか(根が同じか) bool issame(int x, int y){ return root(x) == root(y); } //xを含むグループとyを含むグループを併合する bool unite(int x, int y){ x=root(x), y=root(y); if(x == y)return false; //y側のサイズが小さくなるようにする if(siz[x] < siz[y]) swap(x, y); //yをxの子とする par[y] = x; siz[x] += siz[y]; return true; } int size(int x){ return siz[root(x)]; } }; int roundup(int x, int y){ return (x + y - 1) / y; } int main(){ int n, m; cin >> n >> m; unionfind uni(n * 2); for(int i = 0; i < m; ++i){ int a, b; cin >> a >> b; a--; b--; uni.unite(a, b); } int res = 0; bitset<200000> ck; for(int i = 0; i < n * 2; ++i){ if(!ck[uni.root(i)]){ int sz = uni.size(i); res += sz / 2; ck[uni.root(i)] = 1; } } cout << n - res << endl; }