結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_05 WA -
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 WA -
testcase_11 WA -
testcase_12 WA -
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 WA -
testcase_18 AC 19 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 31 ms
4,380 KB
testcase_21 AC 49 ms
5,172 KB
testcase_22 AC 63 ms
5,700 KB
testcase_23 AC 67 ms
5,700 KB
testcase_24 WA -
testcase_25 AC 67 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