結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー CleyLCleyL
提出日時 2020-01-31 22:16:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 79,620 KB
実行使用メモリ 9,212 KB
最終ジャッジ日時 2023-10-17 10:11:38
合計ジャッジ時間 2,447 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,036 KB
testcase_01 AC 4 ms
6,036 KB
testcase_02 AC 3 ms
6,036 KB
testcase_03 AC 3 ms
6,040 KB
testcase_04 AC 3 ms
6,040 KB
testcase_05 AC 4 ms
6,040 KB
testcase_06 AC 4 ms
6,040 KB
testcase_07 AC 4 ms
6,040 KB
testcase_08 AC 4 ms
6,040 KB
testcase_09 AC 4 ms
6,040 KB
testcase_10 AC 3 ms
6,040 KB
testcase_11 AC 3 ms
6,040 KB
testcase_12 AC 4 ms
6,040 KB
testcase_13 AC 10 ms
6,396 KB
testcase_14 AC 11 ms
6,428 KB
testcase_15 AC 11 ms
6,428 KB
testcase_16 AC 10 ms
6,396 KB
testcase_17 AC 10 ms
6,388 KB
testcase_18 AC 26 ms
7,108 KB
testcase_19 AC 27 ms
7,092 KB
testcase_20 AC 45 ms
7,544 KB
testcase_21 AC 74 ms
8,416 KB
testcase_22 AC 95 ms
9,148 KB
testcase_23 AC 94 ms
9,208 KB
testcase_24 AC 88 ms
9,212 KB
testcase_25 AC 94 ms
9,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <vector>
using namespace std;
//B
struct UnionFind {
  vector<int> par;
  int N;
  UnionFind(int n) : N(n),par(n){
    for(int i = 0; n > i; i++)par[i] = i;
  }

  int root(int n){
    if(par[n] == n)return n;
    return par[n] = root(par[n]);
  }

  void unite(int a,int b){
    int ra = root(a);
    int rb = root(b);
    if(ra==rb)return;
    par[ra] = rb;
  }

  bool same(int a, int b){
    return root(a) == root(b);
  }
  int size(){
    set<int> A;
    for(int i = 0; N > i; i++){
      A.insert(root(i));
    }
    return A.size();
  }
  int rootsize(){
    int re = 0;
    for(int i = 1; N > i; i++){
      if(same(0,i))re++;
    }
    return re+1;
  }

};
//E
int main(){
  int n;cin>>n;
  UnionFind A(n);
  vector<int> Z[100000];
  for(int i = 0; n-1 > i; i++){
    int a,b;cin>>a>>b;
    A.unite(a,b);
    Z[a].push_back(b);
    Z[b].push_back(a);
  }
  if(A.size() == 2){
    //片方の島が1つだけかつ閉路時はBob
    if(A.rootsize() == 1 || A.rootsize() == n-1){
      int hotoke = 1;
      for(int i = 0; n > i; i++){
        if(Z[i].size() != 2)hotoke--;
        if(hotoke < 0){
          break;
        }
      }
      if(hotoke < 0){
        cout << "Alice" << endl;
      }else{
        cout << "Bob" << endl;
      }
    }else{
      cout << "Alice" << endl;
    }
  }else if(A.size() == 1){
    cout << "Bob" << endl;
  }else{
    cout << "Alice" << endl;
  }
}
0