結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
![]() |
提出日時 | 2020-01-31 21:31:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,413 bytes |
コンパイル時間 | 1,998 ms |
コンパイル使用メモリ | 170,120 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 07:15:55 |
合計ジャッジ時間 | 2,744 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; struct UnionFind { vector<int> rank, parent, size; // +1 for 1-indexed nodes UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) { iota(parent.begin(), parent.end(), 0); // parent is itself } int root(int x) { if (x != parent[x]) { parent[x] = root(parent[x]); } return parent[x]; } bool isSame(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { return link(root(x), root(y)); } bool link(int x, int y) { if (x == y) return false; if (rank[x] > rank[y]) { parent[y] = x; size[x] += size[y]; } else { parent[x] = y; size[y] += size[x]; if (rank[x] == rank[y]) { rank[y]++; } } return true; } int getSize(int x) { return size[root(x)]; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint n; cin >> n; UnionFind uf(n); for (int i = 0; i < n - 1; ++i) { int u, v; cin >> u >> v; uf.unite(u, v); } if (uf.getSize(0) == n) { cout << "Bob" << "\n"; } else { cout << "Alice" << "\n"; } return 0; }