結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー sima.tettekesima.tetteke
提出日時 2020-03-09 18:45:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,683 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 170,208 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 05:20:35
合計ジャッジ時間 2,999 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 7 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 7 ms
5,376 KB
testcase_17 AC 7 ms
5,376 KB
testcase_18 AC 19 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 31 ms
5,376 KB
testcase_21 AC 48 ms
5,376 KB
testcase_22 AC 61 ms
5,504 KB
testcase_23 AC 64 ms
5,632 KB
testcase_24 AC 66 ms
5,632 KB
testcase_25 AC 65 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
 
using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;
vector<vector<pi > > F;
vector<vector<pi > > B;
struct UnionFind{
    //ご本体
    vector<ll > tree;
    //高さ
    vector<ll > rank;
    //グループごとのサイズ
    vector<ll > size;
 
    //定義
    UnionFind(ll N) : tree(N), rank(N), size(N){
        for(int i = 0; i < N; i++){
            tree[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
 
    //どの根っこに属しているのか?さかのぼり続ける
    int root(int x){
        if(tree[x] == x){
            return x;
        }
        //経路圧縮
        return tree[x] = root(tree[x]);
    }
 
    //木と木を(高さが低い方に)くっつける
    ll unite(int x, int y){
        int tx = root(x);
        int ty = root(y);
        //xとyの根が同じならくっつけない
        if(tx == ty){
            return 0;
        }
        
        ll s = size[tx] + size[ty];
        ll r = size[tx] * size[ty];
        size[tx] = s;
        size[ty] = s;
 
        //tree[tx] = ty;
        //高くない方にくっつけたい:効果がいまいちわからん
        //下:ランク付けのつもり 
        if(rank[tx] < rank[ty]){
            //小さい方を大きい方
            //txの根が大きい方の根に更新
            tree[tx] = ty; 
        }else{
            tree[ty] = tx;
            //つなげるときに同じ高さだったらつなげた後に高さを+1する
            if(rank[tx] == rank[ty]){
                rank[tx]++;
            }
        }
 
        return r;
 
    }
 
    //同じ木に属しているか?根っこをさかのぼって調べてみる
    bool same(int x, int y){
        int tx = root(x);
        int ty = root(y);
        if(tx == ty){
            return true;
        }else{
            return false;
        }
    }
    //グループのサイズを返す
    int FindSize(int x){
        return size[root(x)];
    }
 
};

int main() {

    ll N;
    cin >> N;

    //初期化
    UnionFind O(N);

    for(ll i = 0; i < N-1; i++){
        ll a, b;
        cin >> a >> b;
        O.unite(a, b);
    }

    if(N == 2){
        cout << "Bob" << endl;
        return 0;
    }

    bool f = true;
    for(ll i = 0; i < N; i++){
        //cout << O.FindSize(i) << endl;
        if(O.FindSize(i) < N){
            f = false;
        }
    }

    if(f == true){
        cout << "Bob" << endl;
    }else{
        cout << "Alice" << endl;
    }

}
0