結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー yuji9511yuji9511
提出日時 2020-01-31 21:27:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,805 bytes
コンパイル時間 1,700 ms
コンパイル使用メモリ 172,620 KB
実行使用メモリ 7,172 KB
最終ジャッジ日時 2023-10-17 08:40:47
合計ジャッジ時間 2,948 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,384 KB
testcase_01 AC 6 ms
6,384 KB
testcase_02 AC 6 ms
6,384 KB
testcase_03 AC 6 ms
6,384 KB
testcase_04 AC 6 ms
6,384 KB
testcase_05 AC 6 ms
6,384 KB
testcase_06 AC 6 ms
6,384 KB
testcase_07 AC 6 ms
6,388 KB
testcase_08 AC 6 ms
6,388 KB
testcase_09 AC 6 ms
6,388 KB
testcase_10 WA -
testcase_11 AC 6 ms
6,388 KB
testcase_12 AC 6 ms
6,388 KB
testcase_13 AC 8 ms
6,388 KB
testcase_14 AC 8 ms
6,388 KB
testcase_15 AC 8 ms
6,388 KB
testcase_16 AC 8 ms
6,388 KB
testcase_17 AC 7 ms
6,388 KB
testcase_18 AC 12 ms
6,388 KB
testcase_19 WA -
testcase_20 AC 16 ms
6,388 KB
testcase_21 AC 23 ms
6,908 KB
testcase_22 AC 29 ms
7,172 KB
testcase_23 AC 33 ms
7,172 KB
testcase_24 AC 30 ms
7,172 KB
testcase_25 AC 33 ms
7,172 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]);
    }
    if(uf.sz(0) == N){
        print("Bob");
    }else{
        print("Alice");
    }

    

}
0