結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
|
| 提出日時 | 2020-01-31 21:26:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,351 bytes |
| コンパイル時間 | 1,467 ms |
| コンパイル使用メモリ | 170,176 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 07:08:19 |
| 合計ジャッジ時間 | 2,717 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind {
//各要素が属する集合の代表(根)を管理する
//もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
vector<int> data;
UnionFind(int sz) : data(sz, -1) {}
bool unite(int x, int y) {
x = find(x);
y = find(y);
bool is_union = (x != y);
if (is_union) {
if (data[x] > data[y]) swap(x, y);
data[x] += data[y];
data[y] = x;
}
return is_union;
}
int find(int x) {
if (data[x] < 0) { //要素xが根である
return x;
} else {
data[x] = find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
return data[x];
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
int size(int x) {
return -data[find(x)];
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
UnionFind uf(n);
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
//--u; --v;
uf.unite(u, v);
}
cout << (uf.size(0) == n ? "Bob" : "Alice") << endl;
return 0;
}