結果
| 問題 |
No.2202 贅沢てりたまチキン
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-05 13:35:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 1,120 bytes |
| コンパイル時間 | 1,734 ms |
| コンパイル使用メモリ | 172,140 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-18 01:34:15 |
| 合計ジャッジ時間 | 4,434 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n, -1) { }
void init(int n) { par.assign(n, -1); }
int root(int x) {
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x) {
return -par[root(x)];
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
UnionFind uf(2 * n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
uf.merge(a, b + n);
uf.merge(a + n, b);
}
bool ok = true;
for (int i = 0; i < n; i++) {
if (!uf.issame(i, i + n)) {
ok = false;
}
}
cout << (ok ? "Yes" : "No") << endl;
}