結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー LaFolia13
提出日時 2023-07-29 16:55:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 175,492 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-11-14 12:20:04
合計ジャッジ時間 4,000 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;
#define ALL(x) x.begin(), x.end()
constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;
struct union_find {
std::vector<int> par;
union_find() {}
union_find(int n) :
par(n+1, -1)
{}
int root(int x) {
if(par[x] < 0) return x;
return par[x] = root(par[x]);
}
int size(int x) {
return -par[root(x)];
}
bool same(int a, int b) {
return root(a) == root(b);
}
bool merge(int a, int b) {
a = root(a), b = root(b);
if(a == b) return false;
if(par[a] > par[b]) std::swap(a, b);
par[a] += par[b];
par[b] = a;
return true;
}
};
int main() {
llong N, M;
cin >> N >> M;
union_find uf(2 * N);
for (int i = 0; i < M; i++) {
llong A, B;
cin >> A >> B;
uf.merge(A, B);
}
set<llong> used;
llong cnt = 0;
for (int i = 1; i <= 2 * N; i++) {
if (used.count(uf.root(i))) {
continue;
}
used.insert(uf.root(i));
cnt += uf.size(i) % 2;
}
cout << cnt / 2 << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0