結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー Y17Y17
提出日時 2020-01-31 21:43:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 2,842 ms
コンパイル使用メモリ 168,584 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 09:05:47
合計ジャッジ時間 4,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_06 AC 2 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 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 18 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 29 ms
4,348 KB
testcase_21 AC 50 ms
4,348 KB
testcase_22 AC 62 ms
4,348 KB
testcase_23 AC 64 ms
4,348 KB
testcase_24 AC 61 ms
4,348 KB
testcase_25 AC 63 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct UnionFind{
    vector<int> tree;

    UnionFind(int n): tree(n+1, -1) {};

    int root(int i){ return tree[i] < 0 ? i : tree[i] = root(tree[i]); }

    bool unite(int i, int j){
        i = root(i), j = root(j);
        if(i == j) return false;
        tree[i] += tree[j], tree[j] = i;
        return true;
    }

    bool same(int i, int j){ return root(i) == root(j); }

    int size(int i){ return -tree[root(i)]; }
};

int main(){
    int n;
    cin >> n;

    UnionFind uf(n);


    int cnt[100010];

    for(int i = 0;i < n-1;i++){
        int a, b; cin >> a >> b;
        cnt[a]++;
        cnt[b]++;

        uf.unite(a, b);
    }

    map<int, int> mp;

    for(int i = 0;i < n;i++){
        mp[uf.root(i)]++;
    }

    if(mp.size() > 2){
        cout << "Alice" << endl;
    }else if(mp.size() == 1){
        cout << "Bob" << endl;
    }else{

        for(int i = 0;i < n;i++){
            if(!(cnt[i] == 2 || cnt[i] == 0)){
                cout << "Alice" << endl;
                return 0;
            }
        }

        cout << "Bob" << endl;
    }

    return 0;
}
0