結果
問題 |
No.2418 情報通だよ!Nafmoくん
|
ユーザー |
![]() |
提出日時 | 2023-08-28 13:30:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 1,180 bytes |
コンパイル時間 | 3,428 ms |
コンパイル使用メモリ | 252,436 KB |
最終ジャッジ日時 | 2025-02-16 15:20:04 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll mod=998244353; ll inf=1009999999999999990; struct unionfind { vector<ll>par,siz; unionfind(ll n): par(n,-1),siz(n,1){} ll root(ll x){ if (par[x]==-1) { return x; }else{ return par[x]=root(par[x]); } } bool issame(ll x,ll y){ return root(x)==root(y); } bool unite(ll x,ll y){ x=root(x); y=root(y); if (x==y) { return false; } if (siz[x]<siz[y]) { swap(x,y); } par[y]=x; siz[x]+=siz[y]; return true; } ll size(ll x){ return siz[root(x)]; } }; int main(){ ll n,m; cin >> n >> m; unionfind uf(n*2); for (ll i = 0; i < m; i++) { ll a,b; cin >> a >> b; a--,b--; uf.unite(a,b); } ll ans=0; for (ll i = 0; i < n*2; i++) { ans+=uf.siz[uf.root(i)]%2; uf.siz[uf.root(i)]=0; } ans/=2; cout << ans << endl; }