結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー sima.tettekesima.tetteke
提出日時 2020-03-09 19:49:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,824 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 175,240 KB
実行使用メモリ 13,152 KB
最終ジャッジ日時 2024-04-26 10:00:02
合計ジャッジ時間 3,732 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 8 ms
6,944 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 8 ms
6,940 KB
testcase_17 AC 8 ms
6,944 KB
testcase_18 AC 23 ms
6,940 KB
testcase_19 AC 24 ms
6,944 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 87 ms
13,056 KB
testcase_24 AC 84 ms
12,928 KB
testcase_25 AC 83 ms
13,152 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 > > G;
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);
    G.assign(N, vector<pi >());
    for(ll i = 0; i < N-1; i++){
        ll v, u;
        cin >> v >> u;
        ll w = 0;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
        O.unite(v, u);
    }


    bool f = true;
    ll sum2 = 0;
    ll sumR = 0;
    for(ll i = 0; i < N; i++){
        //cout << O.FindSize(i) << endl;
        if(G[i].size() >= 2){
            sum2++;
        }
        if(O.FindSize(i) < N){
            sumR++;
        }
    }

    if(sum2 == N-1 || sumR < 1){
        cout << "Bob" << endl;
    }else{
        cout << "Alice" << endl;
    }

}
0