結果
| 問題 |
No.2418 情報通だよ!Nafmoくん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-11 13:27:33 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,273 bytes |
| コンパイル時間 | 1,343 ms |
| コンパイル使用メモリ | 124,416 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-19 14:31:50 |
| 合計ジャッジ時間 | 2,915 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 11 WA * 7 RE * 3 |
ソースコード
#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;
}