結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー firiexpfiriexp
提出日時 2020-01-31 21:34:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,758 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 100,284 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 02:13:40
合計ジャッジ時間 2,757 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,948 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 4 ms
6,944 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 4 ms
6,944 KB
testcase_18 AC 8 ms
6,940 KB
testcase_19 AC 9 ms
6,944 KB
testcase_20 AC 13 ms
6,940 KB
testcase_21 AC 19 ms
6,940 KB
testcase_22 AC 24 ms
6,944 KB
testcase_23 AC 25 ms
6,940 KB
testcase_24 AC 25 ms
6,940 KB
testcase_25 AC 25 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <cassert>
#include <limits>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
    int forest_size;
public:
    explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n) {};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        forest_size--;
        return true;
    }
    int size(){ return forest_size; }
    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int n;
    cin >> n;
    UnionFind uf(n);
    vector<int> as, bs;
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        uf.unite(a, b);
        as.emplace_back(a);
        bs.emplace_back(b);
    }
    if(uf.size() == 1){
        puts("Bob");
        return 0;
    }else if(uf.size() >= 3){
        puts("Alice");
        return 0;
    }

    vector<int> v(n);
    for (int i = 0; i < n-1; ++i) {
        v[as[i]]++;
        v[bs[i]]++;
    }
    for (int i = 0; i < n; ++i) {
        if(uf.size(i) != 1 && v[i] < 2){
            puts("Alice");
            return 0;
        }
    }
    puts("Bob");
    return 0;
}
0