結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
|
| 提出日時 | 2020-05-18 22:30:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 1,455 bytes |
| コンパイル時間 | 1,710 ms |
| コンパイル使用メモリ | 176,164 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-10-01 22:08:50 |
| 合計ジャッジ時間 | 3,064 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:65:11: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
65 | if(a < b) swap(a, b);
| ^~
main.cpp:58:23: note: 'b' was declared here
58 | int a = -1, b;
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
struct UnionFind{
vector<lint> rnk,par,num;
UnionFind(lint N) : rnk(N),par(N),num(N){
init();
}
void init(){
for(lint i = 0;i < rnk.size();i++){
rnk[i] = 0;
par[i] = i;
num[i] = 1;
}
}
lint find(lint x){
if(par[x] == x) return x;
return par[x] = find(par[x]);
}
void unite(lint x,lint y){
x = find(x);
y = find(y);
if(x == y) return;
if(rnk[x] < rnk[y]){
par[x] = y;
num[y] += num[x];
}
else{
par[y] = x;
num[x] += num[y];
if(rnk[x] == rnk[y]) rnk[x]++;
}
}
bool same(lint x,lint y){
return (find(x) == find(y));
}
lint size(lint x){
return num[find(x)];
}
};
signed main(){
int n; cin >> n;
UnionFind tree(n);
vector<vector<int> > G(n);
for(int i = 1; i < n; i++){
int a, b; scanf("%d%d", &a, &b);
tree.unite(a, b);
G[a].push_back(b); G[b].push_back(a);
}
int c = 0;
for(int i = 0; i < n; i++) if(tree.find(i) == i) c++;
string ans;
if(c == 1) ans = "Bob";
if(c > 2) ans = "Alice";
if(c == 2){
int a = -1, b;
for(int i = 0; i < n; i++){
if(tree.find(i) == i){
if(a < 0) a = tree.size(i);
else b = tree.size(i);
}
}
if(a < b) swap(a, b);
if(a == n - 1 && b == 1){
bool ok = true;
for(int i = 0; i < n; i++) if(G[i].size() != 2 && G[i].size() != 0) ok = false;
if(ok) ans = "Bob";
else ans = "Alice";
}
else ans = "Alice";
}
cout << ans << endl;
}