結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー takumi152
提出日時 2023-08-12 13:48:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,506 bytes
コンパイル時間 1,072 ms
コンパイル使用メモリ 104,124 KB
最終ジャッジ日時 2025-02-16 03:41:38
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pii;
const ll mod = 998244353;
struct unionfind {
vector<int> group;
vector<int> rank;
unionfind() {
unionfind(0);
}
unionfind(int n) {
group = vector<int>(n);
rank = vector<int>(n);
for (int i = 0; i < n; i++) group[i] = i;
}
int root(int x) {
if (group[x] == x) return x;
return group[x] = root(group[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rank[rx] > rank[ry]) group[ry] = rx;
else if (rank[ry] > rank[rx]) group[rx] = ry;
else if (rx != ry) {
group[ry] = rx;
rank[rx]++;
}
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<Pii> ab(m);
for (auto &x: ab) cin >> x.first >> x.second;
unionfind uf(n * 2);
for (int i = 0; i < m; i++) {
uf.unite(ab[i].first - 1, ab[i].second - 1);
}
unordered_map<int, int> group_count;
for (int i = 0; i < n * 2; i++) {
group_count[uf.root(i)]++;
}
int odd_count_num = 0;
for (auto &[_, count]: group_count) {
if (count % 2 != 0) odd_count_num++;
}
int ans = odd_count_num / 2;
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0