結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー beetbeet
提出日時 2020-01-31 21:52:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 206,056 KB
実行使用メモリ 5,988 KB
最終ジャッジ日時 2023-10-17 09:27:02
合計ジャッジ時間 3,699 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 20 ms
4,348 KB
testcase_20 AC 32 ms
4,776 KB
testcase_21 AC 53 ms
5,400 KB
testcase_22 AC 69 ms
5,880 KB
testcase_23 AC 71 ms
5,988 KB
testcase_24 AC 68 ms
5,988 KB
testcase_25 AC 72 ms
5,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0