結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-31 23:37:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,668 bytes |
| コンパイル時間 | 619 ms |
| コンパイル使用メモリ | 66,332 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 11:01:30 |
| 合計ジャッジ時間 | 1,979 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 5 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for(int i = 0; i < N; i++) par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); //xの根をrx
int ry = root(y); //yの根をry
if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main(){
int n; cin >> n;
UnionFind tree(n);
vector<int> v(n);
for(int i=0;i<n-1;i++){
int a,b; cin >> a >> b;
tree.unite(a,b);
v[a]++; v[b]++;
}
sort(v.begin(), v.end());
if(v[0]==0){
bool ff = true;
for(int i=1;i<n;i++) if(v[i]!=2) ff = false;
if(ff){
cout << "Bob" << endl;
return 0;
}
}
bool f = false;
for(int i=1;i<n;i++){
if(!tree.same(0,i)){
f = true;
break;
}
}
if(f) cout << "Alice" << endl;
else cout << "Bob" << endl;
return 0;
}