結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー dyktr_06
提出日時 2023-06-21 01:47:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,285 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 197,812 KB
最終ジャッジ日時 2025-02-14 23:46:38
ジャッジサーバーID
(参考情報)
judge7 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
struct UnionFind{
vector<int> par;
vector<int> edg;
UnionFind(int N) : par(N), edg(N){
for(int i = 0; i < N; ++i){
par[i] = -1;
edg[i] = 0;
}
}
int root(int x){
if(par[x] < 0) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y){
int rx = root(x);
int ry = root(y);
if(rx == ry){
edg[rx]++;
return;
}
par[ry] = par[rx] + par[ry];
par[rx] = ry;
edg[ry] += edg[rx] + 1;
}
bool same(int x, int y){
int rx = root(x);
int ry = root(y);
return rx == ry;
}
long long size(int x){
return -par[root(x)];
}
long long edge(int x){
return edg[root(x)];
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m; cin >> n >> m;
assert(1 <= n <= 100000);
assert(0 <= m <= 100000);
UnionFind uf(2 * n);
for(int i = 0; i < m; i++){
int u, v; cin >> u >> v;
u--, v--;
uf.unite(u, v);
}
int ans = 0;
for(int i = 0; i < 2 * n; i++){
if(uf.root(i) == i && uf.size(i) % 2) ans++;
}
cout << ans / 2 << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0