結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー CleyLCleyL
提出日時 2020-01-31 21:42:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,007 bytes
コンパイル時間 1,460 ms
コンパイル使用メモリ 72,204 KB
実行使用メモリ 9,196 KB
最終ジャッジ日時 2023-10-17 09:04:33
合計ジャッジ時間 3,084 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,020 KB
testcase_01 AC 4 ms
6,020 KB
testcase_02 AC 4 ms
6,020 KB
testcase_03 AC 4 ms
6,020 KB
testcase_04 AC 3 ms
6,020 KB
testcase_05 AC 4 ms
6,024 KB
testcase_06 AC 4 ms
6,024 KB
testcase_07 AC 4 ms
6,024 KB
testcase_08 AC 4 ms
6,024 KB
testcase_09 AC 4 ms
6,024 KB
testcase_10 WA -
testcase_11 AC 3 ms
6,024 KB
testcase_12 AC 3 ms
6,024 KB
testcase_13 AC 11 ms
6,380 KB
testcase_14 AC 10 ms
6,340 KB
testcase_15 AC 10 ms
6,340 KB
testcase_16 AC 10 ms
6,380 KB
testcase_17 AC 10 ms
6,372 KB
testcase_18 AC 27 ms
7,092 KB
testcase_19 WA -
testcase_20 AC 42 ms
7,528 KB
testcase_21 AC 67 ms
8,368 KB
testcase_22 AC 89 ms
9,132 KB
testcase_23 AC 95 ms
9,192 KB
testcase_24 AC 88 ms
9,196 KB
testcase_25 AC 94 ms
9,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
//B
struct UnionFind {
  vector<int> par;
  UnionFind(int 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);
  }

};
//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);
  }
  bool nya = false;
  for(int i = 1; n > i; i++){
    if(!A.same(0,i)){
      nya = true;
      break;
    }
  }
  int nw = 0;
  bool z = false;
  for(int i = 0; n > i; i++){
    if(0 == Z[i].size()){
      nw++;
    }else if(1 == Z[i].size()){
      z = true;
    }
  }
  if((nya+z)+nw > 1){
    cout << "Alice" << endl;
  }else{
    cout << "Bob" << endl;
  }
}
0