結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー tonegawatonegawa
提出日時 2020-02-01 00:27:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,825 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 104,488 KB
実行使用メモリ 5,148 KB
最終ジャッジ日時 2023-10-17 14:39:42
合計ジャッジ時間 2,755 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 8 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 20 ms
4,348 KB
testcase_19 AC 20 ms
4,348 KB
testcase_20 AC 32 ms
4,356 KB
testcase_21 AC 53 ms
4,884 KB
testcase_22 AC 66 ms
5,148 KB
testcase_23 AC 66 ms
5,148 KB
testcase_24 AC 66 ms
5,148 KB
testcase_25 AC 66 ms
5,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct UF{
  std::vector<int> par, dep, sz;
  UF(int n){
    par.resize(n+1), dep.resize(n+1), sz.resize(n+1);
    init(n);
  }
  void init(int nu) {
    for(int iu=0;iu<=nu;iu++){
      par[iu] = iu;
      dep[iu] = 0;
      sz[iu] = 1;
    }
  }
  int find(int xu){
    if(par[xu] == xu) return xu;
    return par[xu] = find(par[xu]);
  }
  void unite(int xu, int yu){
    xu=find(xu);
    yu=find(yu);
    if(xu == yu) return;
    if(dep[xu] < dep[yu]){
      sz[yu] += sz[xu];
      par[xu] = yu;
    }else{
      par[yu] = xu;
      sz[xu] += sz[yu];
      if(dep[xu] == dep[yu]) dep[xu]++;
    }
  }
  bool same(int xu, int yu){
    return find(xu) == find(yu);
  }
};
int main(int argc, char const *argv[]) {
  ll a, b, n;std::cin >> n;
  UF uf(n+1);
  vll c(n, 0);
  re(i, n-1){
    std::cin >> a >> b;
    uf.unite(a, b);
    c[a]++, c[b]++;
  }
  set<ll> s;
  re(i, n) s.insert(uf.find(i));
  if(s.size()==1){
    std::cout << "Bob" << '\n';
    return 0;
  }
  if(s.size()==2){
    ll t = 0;
    re(i, n) if(c[i]==2) t++;
    if(t==n-1) std::cout << "Bob" << '\n';
    else std::cout << "Alice" << '\n';
    return 0;
  }
  std::cout << "Alice" << '\n';
  return 0;
}
0