結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー CleyLCleyL
提出日時 2020-01-31 22:07:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 79,284 KB
実行使用メモリ 9,144 KB
最終ジャッジ日時 2023-10-17 09:56:59
合計ジャッジ時間 2,031 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,968 KB
testcase_01 AC 3 ms
5,968 KB
testcase_02 AC 3 ms
5,968 KB
testcase_03 AC 3 ms
5,972 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
5,972 KB
testcase_07 AC 3 ms
5,972 KB
testcase_08 AC 3 ms
5,972 KB
testcase_09 AC 3 ms
5,972 KB
testcase_10 AC 4 ms
5,972 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 9 ms
6,328 KB
testcase_14 AC 9 ms
6,360 KB
testcase_15 AC 9 ms
6,360 KB
testcase_16 AC 9 ms
6,328 KB
testcase_17 WA -
testcase_18 AC 22 ms
7,040 KB
testcase_19 AC 22 ms
7,024 KB
testcase_20 AC 37 ms
7,476 KB
testcase_21 AC 60 ms
8,348 KB
testcase_22 AC 73 ms
9,116 KB
testcase_23 AC 73 ms
9,140 KB
testcase_24 WA -
testcase_25 AC 74 ms
9,140 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){
      cout << "Bob" << endl;
    }else{
      cout << "Alice" << endl;
    }
  }else if(A.size() == 1){
    cout << "Bob" << endl;
  }else{
    cout << "Alice" << endl;
  }
}
0