結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー betrue12betrue12
提出日時 2020-01-31 21:31:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,256 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 205,760 KB
実行使用メモリ 4,440 KB
最終ジャッジ日時 2023-10-17 08:47:13
合計ジャッジ時間 3,353 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 18 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 30 ms
4,348 KB
testcase_21 AC 47 ms
4,348 KB
testcase_22 AC 60 ms
4,440 KB
testcase_23 AC 64 ms
4,440 KB
testcase_24 AC 62 ms
4,440 KB
testcase_25 AC 64 ms
4,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sz[find(x)];
    }
};

int main(){
    int N;
    cin >> N;
    UnionFind uf(N);
    vector<int> deg(N);
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        deg[a]++;
        deg[b]++;
        uf.unite(a, b);
    }
    int cmp = 0, one = 0;
    for(int i=0; i<N; i++){
        if(uf.find(i) == i) cmp++;
        if(deg[i] == 1) one++;
    }
    if(one) cmp++;
    cout << (cmp >= 3 ? "Alice" : "Bob") << endl;
    return 0;
}
0