結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー shin3110shin3110
提出日時 2023-08-12 14:02:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 3,173 bytes
コンパイル時間 4,087 ms
コンパイル使用メモリ 229,308 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 04:46:13
合計ジャッジ時間 4,853 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 19 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 14 ms
5,376 KB
testcase_06 AC 13 ms
5,376 KB
testcase_07 AC 15 ms
5,376 KB
testcase_08 AC 12 ms
5,376 KB
testcase_09 AC 18 ms
5,376 KB
testcase_10 AC 19 ms
5,376 KB
testcase_11 AC 16 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 21 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 10 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 13 ms
5,376 KB
testcase_21 AC 7 ms
5,376 KB
testcase_22 AC 9 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*

              ∧∧∩ 
             ( ゚∀゚)/ キタ━━━━━━(゚∀゚)━━━━━━!!!!  
            ⊂   ノ  ゆっくり見てってね!!!!!!!!
             (つ ノ
    o          (ノ
     \      ☆
             |      o
          (⌒ ⌒ヽ   /     ☆
    \  (´⌒  ⌒  ⌒ヾ   /
      ('⌒ ; ⌒   ::⌒  )
     (´     )     ::: ) /
  ☆─ (´⌒;:    ::⌒`) :;  )

*/
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

bool printb(bool f) {
	if (f) cout << "Yes\n";
	else cout << "No\n";
	return f;
}

#define elif else if
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(a) a.begin(), a.end()
// xを2進数にした際にi桁目が0か1か
#define bit(x,i)((x>>i)&1)
typedef long long ll;
typedef long double ld;

ld pi = 3.14159265358979;

inline void scan(){}
template<class Head,class... Tail>
inline void scan(Head&head,Tail&... tail){std::cin>>head;scan(tail...);}
 
// print(a, b, c) => cout << a << ' ' << b << ' ' << c << endl;
inline void print(){}
template<class Head,class... Tail>
inline void print(Head&head,Tail&... tail){std::cout<<head<<" ";print(tail...);cout<<endl;}

//vectorのcout,cin
template<typename T>
std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T>
std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}

// 2地点の距離(long double)
long double coor_dist(long double xi, long double yi, long double xj, long double yj) {
    return sqrt(abs((xi - xj) * (xi - xj)) + abs((yi - yj) * (yi - yj)));
}

// 回文かどうかの判定
bool iskaibun(string s){ll k = s.size();rep(i,0,k/2){if(s[i]!=s[k-1-i]){return false;}}return true;}



struct UnionFind {
    vector<int> par;
    UnionFind(int n=0): par(n,-1) {}
    int find(int x) {
        if (par[x] < 0) return x;
        return find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return ;
        if (size(x) < size(y)) swap(x,y);
        par[x] += par[y];
        par[y] = x;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return true;
        else return false;
    }
    int size(int x) { 
        return -par[find(x)];
    }
};

// UnionFind uf(n);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m; cin >> n >> m;
    n *= 2;
    UnionFind uf(n);
    rep(i, 0, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }
    vector<int> cnt(n, 0);
    rep(i, 0, n) {
        cnt[uf.find(i)]++;
    }
    int ans = 0;
    rep(i, 0, n) if(cnt[i]%2 == 1) ans++;
    cout << ans/2 << endl;
}
0