結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
leaf_1415
|
| 提出日時 | 2020-01-31 21:36:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 2,000 ms |
| コード長 | 1,294 bytes |
| コンパイル時間 | 776 ms |
| コンパイル使用メモリ | 71,652 KB |
| 実行使用メモリ | 9,600 KB |
| 最終ジャッジ日時 | 2024-09-17 07:20:55 |
| 合計ジャッジ時間 | 2,114 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#define llint long long
using namespace std;
struct UnionFind{
int size;
vector<int> parent;
UnionFind(){}
UnionFind(int size){
this->size = size;
parent.resize(size+1);
init();
}
void init(){
for(int i = 0; i <= size; i++) parent[i] = i;
}
int root(int i){
if(parent[i] == i) return i;
return parent[i] = root(parent[i]);
}
bool same(int i, int j){
return root(i) == root(j);
}
void unite(int i, int j){
int root_i = root(i), root_j = root(j);
if(root_i == root_j) return;
parent[root_i] = root_j;
}
};
llint n;
vector<llint> G[100005];
UnionFind uf(100005);
set<llint> S;
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
llint u, v;
for(int i = 1; i <= n-1; i++){
cin >> u >> v;
u++, v++;
G[u].push_back(v);
G[v].push_back(u);
uf.unite(u, v);
}
for(int i = 1; i <= n; i++) S.insert(uf.root(i));
if(S.size() >= 3){
cout << "Alice" << endl;
return 0;
}
if(S.size() == 1){
cout << "Bob" << endl;
return 0;
}
bool flag0 = false, flag2 = true;
for(int i = 1; i <= n; i++){
if(G[i].size() != 2){
if(G[i].size() == 0) flag0 = true;
else flag2 = false;
}
}
if(flag0 && flag2) cout << "Bob" << endl;
else cout << "Alice" << endl;
return 0;
}
leaf_1415