結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー yuji9511yuji9511
提出日時 2020-01-31 21:37:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,952 bytes
コンパイル時間 1,809 ms
コンパイル使用メモリ 181,584 KB
実行使用メモリ 7,204 KB
最終ジャッジ日時 2023-10-17 08:56:23
合計ジャッジ時間 3,140 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,416 KB
testcase_01 AC 6 ms
6,416 KB
testcase_02 AC 5 ms
6,416 KB
testcase_03 AC 5 ms
6,416 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 5 ms
6,416 KB
testcase_07 AC 5 ms
6,420 KB
testcase_08 AC 6 ms
6,420 KB
testcase_09 AC 5 ms
6,420 KB
testcase_10 AC 5 ms
6,420 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 8 ms
6,420 KB
testcase_14 AC 7 ms
6,420 KB
testcase_15 AC 7 ms
6,420 KB
testcase_16 AC 7 ms
6,420 KB
testcase_17 WA -
testcase_18 AC 12 ms
6,420 KB
testcase_19 AC 12 ms
6,420 KB
testcase_20 AC 17 ms
6,420 KB
testcase_21 AC 25 ms
6,940 KB
testcase_22 AC 32 ms
7,204 KB
testcase_23 AC 32 ms
7,204 KB
testcase_24 WA -
testcase_25 AC 33 ms
7,204 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);
    rep(i,0,N-1){
        cin >> u[i] >> v[i];
        uf.unite(u[i], v[i]);
    }
    ll max_val = 0;
    map<ll,ll> mp;
    rep(i,0,N){
        mp[uf.sz(i)]++;
    }
    if(mp[N] > 0){
        print("Bob");
    }else if(mp[N-1] == N-1 && mp[1] == 1){
        print("Bob");
    }else{
        print("Alice");
    }

    

}
0