結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー hogepagefoobarhogepagefoobar
提出日時 2020-02-02 16:54:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 171,332 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 01:18:35
合計ジャッジ時間 3,718 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 7 ms
4,348 KB
testcase_18 AC 20 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 31 ms
4,348 KB
testcase_21 AC 47 ms
4,348 KB
testcase_22 AC 60 ms
4,348 KB
testcase_23 AC 67 ms
4,348 KB
testcase_24 AC 62 ms
4,348 KB
testcase_25 AC 64 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

struct UFT {
    vector<int> parent;

    UFT(int n) {
        parent.resize(n);
        rep(i, n) parent[i] = i;
    }

    int root(int x) {
        if (x == parent[x])
            return x;
        return parent[x] = root(parent[x]);
    }

    bool samegroup(int x, int y) { return root(x) == root(y); }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)
            return;
        // TODO: no rank check
        parent[x] = y;
    }

    int groups() {
        int ans = 0;
        rep(i, parent.size()) {
            if (root(i) == i) {
                ans++;
            }
        }
        return ans;
    }

    void dump() {
        rep(i, parent.size()) { printf("%d\t%d\n", i, root(i)); }
    }
};
int main(int argc, char** argv) {
    int n;
    cin >> n;
    int u, v;
    vector<int> bridges(n);

    UFT t(n);

    rep(i, n - 1) {
        cin >> u >> v;
        bridges[u]++;
        bridges[v]++;
        t.unite(u, v);
    }

    int one = 0;
    rep(i, n) {
        if (bridges[i] == 1) {
            one++;
        }
    }

    // cout << "goups:" << t.groups() << endl;
    // cout << "oneorless:" << one << endl;
    if (t.groups() >= 3 || (t.groups() == 2 && one >= 1))
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;

    return 0;
};
0