結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー azzazz
提出日時 2020-01-31 22:22:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 6,075 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 192,088 KB
実行使用メモリ 9,300 KB
最終ジャッジ日時 2023-10-17 10:21:34
合計ジャッジ時間 3,345 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,024 KB
testcase_01 AC 4 ms
6,024 KB
testcase_02 AC 4 ms
6,024 KB
testcase_03 AC 4 ms
6,024 KB
testcase_04 AC 4 ms
6,028 KB
testcase_05 AC 4 ms
6,028 KB
testcase_06 AC 4 ms
6,028 KB
testcase_07 AC 4 ms
6,032 KB
testcase_08 AC 3 ms
6,032 KB
testcase_09 AC 4 ms
6,032 KB
testcase_10 AC 4 ms
6,032 KB
testcase_11 AC 4 ms
6,032 KB
testcase_12 AC 4 ms
6,032 KB
testcase_13 AC 7 ms
6,356 KB
testcase_14 AC 7 ms
6,392 KB
testcase_15 AC 7 ms
6,388 KB
testcase_16 AC 7 ms
6,356 KB
testcase_17 AC 7 ms
6,572 KB
testcase_18 AC 14 ms
7,008 KB
testcase_19 AC 16 ms
7,668 KB
testcase_20 AC 24 ms
7,812 KB
testcase_21 AC 38 ms
8,456 KB
testcase_22 AC 49 ms
9,124 KB
testcase_23 AC 50 ms
9,296 KB
testcase_24 AC 45 ms
9,300 KB
testcase_25 AC 50 ms
9,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){cout << (v[i]) << " ";} cout << endl;
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

ll gcd(ll a, ll b) {
    if(a < b) swap(a,b);
    
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return (a/g)*b;
}

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 約数列挙 O(√n)
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        ll num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(ll &a, ll b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(ll &a, ll b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

ll powM(ll a,ll b) {
    ll ret = 1;
    ll tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % MOD;
        tmp = (tmp * tmp) % MOD;
        b = b >> 1;
    }
    return ret;
}

// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// ラングレンス圧縮
vector<pair<char, int>> rang_com(string s){
  vector<pair<char, int>> ret;
  string t = s;
  t.erase(unique(all(t)), t.end());
  int now = 0;
  int pre = 0;
  for(auto ct : t){
    while(now < s.size() && s[now] == ct) now++;
    if(ret.size() == 0){
      ret.push_back({ct, now});
    } else {
      ret.push_back({ct, now - pre});
    }
    pre = now;
  }
  return ret;
}

struct UnionFind {
    vector<int> par;
    vector<int> sz;
    map<int, int> szmp; // map<size, cnt>
 
    UnionFind(int n = 0){
        if(n > 0) initialize(n);
    }
 
    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            sz[i] = 1;
        }
        szmp[1] = n;
    }
 
    int find(int x){
        if(par[x] == x){
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
 
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sz[x] > sz[y]) swap(x, y);
 
        for(int s : {sz[x], sz[y]}){
            szmp[s]--;
            if(szmp[s] == 0) szmp.erase(s);
        }
        par[x] = y;
        sz[y] += sz[x];
        szmp[sz[y]]++;
    }
 
    bool same(int x, int y){
        return find(x) == find(y);
    }
 
    int size(int x){
        return sz[find(x)];
    }
 
    int minsz(){
        return szmp.begin() -> first;
    }

    int unitenum(){
        return szmp.size();
    }
};

vector<int> g[(int)1e5];
bool isVist[(int)1e5];

int dfs(int s){
  int ret = 1;
  isVist[s] = true;
  for(int v : g[s]){
    if(isVist[v]) continue;
    ret += dfs(v);
  }
  return ret;
}


int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);  

  int n;
  cin >> n;

  REP(i, n - 1){
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  int cnt = 0;
  vector<int> vec;
  REP(i, n){
    if(isVist[i]) continue;
    cnt++;
    vec.push_back(dfs(i));
  }
  sort(all(vec), greater<>());

  if(cnt == 1){
    cout << "Bob" << endl;
  } else if(cnt == 2 && vec[0] == n - 1){
    bool chk = true;
    int cnt2 = 0;
    REP(i, n){
      if(g[i].size() == 0) cnt2++;
      else if(g[i].size() != 2) chk = false;
    }
    if(cnt2 == 1 && chk) {
      cout << "Bob" << endl;
    } else {
      cout << "Alice" << endl;
    }
  } else {
    cout << "Alice" << endl;
  }

  return 0;
}
0