結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー ryota2357ryota2357
提出日時 2023-07-11 13:27:33
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,273 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 123,776 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 02:51:36
合計ジャッジ時間 3,754 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 57 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 37 ms
5,376 KB
testcase_09 AC 53 ms
5,376 KB
testcase_10 AC 61 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 AC 39 ms
5,376 KB
testcase_16 AC 62 ms
5,376 KB
testcase_17 RE -
testcase_18 AC 28 ms
5,376 KB
testcase_19 WA -
testcase_20 RE -
testcase_21 AC 21 ms
5,376 KB
testcase_22 AC 24 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
#include <map>
#include <vector>
using namespace std;

struct UnionFind
{
    vector<int> data;
    const uint __size;
    UnionFind(const int size = 0) noexcept : data(size, -1), __size(max(0, size)) {}
    inline int root(const int& x) {
        if (data[x] < 0) return x;
        return data[x] = root(data[x]);
    }
    inline bool unite(const int& x, const int& y) {
        int rx = root(x), ry = root(y);
        if (rx == ry) return false;
        if (data[rx] > data[ry]) swap(rx, ry);
        data[rx] += data[ry];
        data[ry] = rx;
        return true;
    }
    inline bool same(const int& x, const int& y) { return root(x) == root(y); }
    inline int size(const int& x) { return -data[root(x)]; }
};

int main() {
    int n, m;
    cin >> n >> m;
    assert(1 <= n && n <= 100000);
    assert(0 <= m && m <= 100000);
    UnionFind uf(2 * n);

    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        assert(1 <= a && a <= 2 * n);
        assert(1 <= b && b <= 2 * n);
        uf.unite(a, b);
    }

    int ans = 0;
    for (int i = 1; i <= 2 * n; ++i) {
        if (uf.root(i) == i && uf.size(i) % 2) {
             ans += 1;
        }
    }
    cout << ans / 2 << endl;
    return 0;
}
0