結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー yuji9511yuji9511
提出日時 2020-01-31 21:41:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 2,199 bytes
コンパイル時間 4,660 ms
コンパイル使用メモリ 174,000 KB
実行使用メモリ 13,276 KB
最終ジャッジ日時 2023-10-17 09:02:34
合計ジャッジ時間 3,646 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
7,992 KB
testcase_01 AC 7 ms
7,992 KB
testcase_02 AC 7 ms
7,992 KB
testcase_03 AC 7 ms
7,992 KB
testcase_04 AC 7 ms
7,992 KB
testcase_05 AC 7 ms
7,992 KB
testcase_06 AC 7 ms
7,992 KB
testcase_07 AC 8 ms
7,996 KB
testcase_08 AC 7 ms
7,996 KB
testcase_09 AC 7 ms
7,996 KB
testcase_10 AC 7 ms
7,996 KB
testcase_11 AC 7 ms
7,996 KB
testcase_12 AC 7 ms
7,996 KB
testcase_13 AC 10 ms
8,524 KB
testcase_14 AC 11 ms
8,524 KB
testcase_15 AC 11 ms
8,524 KB
testcase_16 AC 10 ms
8,524 KB
testcase_17 AC 10 ms
8,524 KB
testcase_18 AC 19 ms
9,580 KB
testcase_19 AC 18 ms
9,316 KB
testcase_20 AC 26 ms
10,108 KB
testcase_21 AC 40 ms
11,428 KB
testcase_22 AC 52 ms
12,484 KB
testcase_23 AC 58 ms
13,276 KB
testcase_24 AC 57 ms
13,276 KB
testcase_25 AC 62 ms
13,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
struct UnionFind {
private:
    ll N;
    vector<ll> parent;
    vector<ll> num;
    vector<ll> diff_weight;

public:
    UnionFind(ll n){
        N = n;
        rep(i,0,N) parent.push_back(i);
        rep(i,0,N) num.push_back(1);
        rep(i,0,N) diff_weight.push_back(0);
    }

    ll root(ll x){
        if(x == parent[x]){
            return x;
        }else{
            ll r = root(parent[x]);
            diff_weight[x] += diff_weight[parent[x]];
            return parent[x] = r;
        }
    }

    void unite(ll a, ll b, ll w = 0){
        w += weight(a); w -= weight(b);
        a = root(a); b = root(b);
        if(a == b) return;
        parent[b] = a;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
        diff_weight[b] = w;
    }

    bool same(ll a, ll b){ return root(a) == root(b);}
    
    ll sz(ll x){ return num[root(x)];}

    ll weight(ll x){
        root(x);
        return diff_weight[x];
    }

    ll diff(ll a, ll b){
        return weight(b) - weight(a);
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll u[100010], v[100010];
    UnionFind uf(100010);
    vector<ll> tree[100010];
    rep(i,0,N-1){
        cin >> u[i] >> v[i];
        uf.unite(u[i], v[i]);
        tree[u[i]].push_back(v[i]);
        tree[v[i]].push_back(u[i]);
    }
    if(uf.sz(0) == N){
        print("Bob");
    }else{
        bool is_N1 = false, ok = true;
        rep(i,0,N){
            if(uf.sz(i) == N-1){
                is_N1 = true;
            }
            if(uf.sz(i) == N-1 && tree[i].size() != 2) ok = false;
        }
        if(is_N1 && ok){
            print("Bob");
        }else{
            print("Alice");
        }
    }

    

}
0