結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
oxyshower
|
| 提出日時 | 2020-02-01 15:13:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 57 ms / 2,000 ms |
| コード長 | 1,192 bytes |
| コンパイル時間 | 1,504 ms |
| コンパイル使用メモリ | 173,868 KB |
| 実行使用メモリ | 5,632 KB |
| 最終ジャッジ日時 | 2024-09-18 20:02:14 |
| 合計ジャッジ時間 | 2,688 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long
struct UnionFind{
vector<int> par; //親
vector<int> size; //集合の大きさ
UnionFind(int n){
par.resize(n); size.resize(n, 1);
for(int i = 0; i < n; i++){
par[i] = i;
}
}
//木の根を求める
int root(int x){
if(par[x] == x){
return x;
}else{
return par[x] = root(par[x]);
}
}
//xとyの属する集合を併合
void unite(int x,int y){
x = root(x), y = root(y);
if(x == y) return;
if(size[x] < size[y]) swap(x,y);
par[y] = x;
size[x] += size[y];
}
bool same(int x, int y){
return root(x) == root(y);
}
};
signed main(){
int n; cin >> n;
UnionFind uf(n);
vector<int> indeg(n, 0);
for(int i = 0; i < n-1; i++){
int u, v; cin >> u >> v;
uf.unite(u, v);
indeg[u]++;
indeg[v]++;
}
if(uf.size[uf.root(0)] == n-1){
int cnt = 0;
for(int i = 0; i < n; i++){
if(indeg[i] < 2) cnt++;
}
cout << (cnt < 2 ? "Bob" : "Alice") << endl;
}else{
cout << (uf.size[uf.root(0)] == n ? "Bob" : "Alice") << endl;
}
return 0;
}
oxyshower