結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
|
| 提出日時 | 2020-03-05 19:30:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,473 bytes |
| コンパイル時間 | 859 ms |
| コンパイル使用メモリ | 71,724 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-14 02:04:11 |
| 合計ジャッジ時間 | 2,036 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 8 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
class UnionFind {
vector<uint64_t> parent;
public:
vector<uint64_t> digree;
UnionFind(uint64_t N) : parent(N), digree(N) {
for(uint64_t i=0; i<N; i++){
parent[i] = i;
digree[i] = 0;
}
}
void unite(uint64_t x, uint64_t y){
uint64_t rx = root(x);
uint64_t ry = root(y);
digree[x] += 1;
digree[y] += 1;
if(rx == ry) {
} else {
parent[rx] = ry;
}
}
bool isSame(uint64_t x, uint64_t y){
uint64_t rx = root(x);
uint64_t ry = root(y);
return rx == ry;
}
int root(uint64_t x){
if (parent[x] == x) return x;
return parent[x] = root(parent[x]);
}
};
int main()
{
int N;
cin >> N;
UnionFind uf(N);
for(int n=0; n<N-1; n++){
int u, v;
cin >> u >> v;
uf.unite(u, v);
}
int root1=-1, root2=-1;
for(int n=0; n<N; n++){
if(root1==-1){
root1 = uf.root(n);
} else if(uf.root(n) == root1 && root2 == -1){
root2 = uf.root(n);
} else {
cout << "Alice" << endl;
return 0;
}
}
if(root2 == -1){
cout << "Bob" << endl;
return 0;
} else {
if(uf.digree[root2] == 0){
root2 = root1;
} else if(uf.digree[root1] != 0){
cout << "Alice" << endl;
return 0;
}
for(int n=0; n<N; n++){
if(uf.root(n) == root2 && uf.digree[n] != 2){
cout << "Alice" << endl;
return 0;
}
}
cout << "Bob" << endl;
return 0;
}
}