結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
beet
|
| 提出日時 | 2020-01-31 21:52:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 1,220 bytes |
| コンパイル時間 | 2,044 ms |
| コンパイル使用メモリ | 198,140 KB |
| 最終ジャッジ日時 | 2025-01-08 21:03:47 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
struct UnionFind{
Int num;
vector<Int> rs,ps;
UnionFind(){}
UnionFind(Int n):num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}
Int find(Int x){
return (x==ps[x]?x:ps[x]=find(ps[x]));
}
bool same(Int x,Int y){
return find(x)==find(y);
}
void unite(Int x,Int y){
x=find(x);y=find(y);
if(x==y) return;
if(rs[x]<rs[y]) swap(x,y);
rs[x]+=rs[y];
ps[y]=x;
num--;
}
Int size(Int x){
return rs[find(x)];
}
Int count() const{
return num;
}
};
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
//INSERT ABOVE HERE
signed main(){
Int n;
cin>>n;
UnionFind uf(n);
vector<Int> deg(n);
for(Int i=1;i<n;i++){
Int a,b;
cin>>a>>b;
uf.unite(a,b);
deg[a]++;
deg[b]++;
}
if(uf.count()==1) drop("Bob");
if(uf.count()==3) drop("Alice");
if(uf.count()==2&&*max_element(deg.begin(),deg.end())==2)
for(Int i=0;i<n;i++)
if(uf.size(i)==1) drop("Bob");
drop("Alice");
return 0;
}
beet