結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー oxyshoweroxyshower
提出日時 2020-02-01 15:13:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,192 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 172,668 KB
実行使用メモリ 5,700 KB
最終ジャッジ日時 2023-10-19 00:03:24
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 31 ms
4,380 KB
testcase_21 AC 49 ms
5,172 KB
testcase_22 AC 62 ms
5,700 KB
testcase_23 AC 65 ms
5,700 KB
testcase_24 AC 64 ms
5,700 KB
testcase_25 AC 66 ms
5,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct UnionFind{
  vector<int> par; //親
  vector<int> size; //集合の大きさ

  UnionFind(int n){
    par.resize(n); size.resize(n, 1);
    for(int i = 0; i < n; i++){
      par[i] = i;
    }
  }

  //木の根を求める
  int root(int x){
    if(par[x] == x){
      return x;
    }else{
      return par[x] = root(par[x]);
    }
  }

  //xとyの属する集合を併合
  void unite(int x,int y){
    x = root(x), y = root(y);
    if(x == y) return;
    if(size[x] < size[y]) swap(x,y);
    par[y] = x;
    size[x] += size[y];
  }

  bool same(int x, int y){
    return root(x) == root(y);
  }
};

signed main(){

  int n; cin >> n;
  UnionFind uf(n);
  vector<int> indeg(n, 0);
  for(int i = 0; i < n-1; i++){
    int u, v; cin >> u >> v;
    uf.unite(u, v);
    indeg[u]++;
    indeg[v]++;
  }
  if(uf.size[uf.root(0)] == n-1){
    int cnt = 0;
    for(int i = 0; i < n; i++){
      if(indeg[i] < 2) cnt++;
    }
    cout << (cnt < 2 ? "Bob" : "Alice") << endl;
  }else{
    cout << (uf.size[uf.root(0)] == n ? "Bob" : "Alice") << endl;
  }

  return 0;
}
0