結果
問題 | No.2202 贅沢てりたまチキン |
ユーザー |
|
提出日時 | 2024-11-13 01:02:27 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 135 ms / 2,000 ms |
コード長 | 1,271 bytes |
コンパイル時間 | 3,203 ms |
コンパイル使用メモリ | 249,144 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-13 01:02:34 |
合計ジャッジ時間 | 7,179 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(),(a).end() struct UnionFind { vector<int> par, siz; int v, group; UnionFind(int n) { par = vector<int>(n, -1); siz = vector<int>(n, 1); v = n; group = n; } int root(int x) { if (par[x] == -1) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; group--; return true; } int size(int x) { return siz[root(x)]; } }; int main() { cin.tie(nullptr); int N, M; cin >> N >> M; UnionFind uf(N * 2); rep(i, 0, M) { int A, B; cin >> A >> B; A--, B--; uf.unite(2*A, 2*B + 1); uf.unite(2*A + 1, 2*B); } bool ok = true; rep(i, 0, N) if (!uf.same(2*i, 2*i + 1)) ok = false; if (ok) cout << "Yes\n"; else cout << "No\n"; }