結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 WA -
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 7 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 8 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 30 ms
4,348 KB
testcase_21 AC 45 ms
4,348 KB
testcase_22 AC 57 ms
4,348 KB
testcase_23 AC 62 ms
4,348 KB
testcase_24 AC 61 ms
4,348 KB
testcase_25 AC 62 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;

    UFT t(n);

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

    // cout << t.groups() << endl;
    if (t.groups() >= 2)
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;

    return 0;
};
0