結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー kibunakibuna
提出日時 2020-01-31 21:49:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,801 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 172,472 KB
実行使用メモリ 5,356 KB
最終ジャッジ日時 2023-10-17 09:22:37
合計ジャッジ時間 2,865 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 8 ms
4,348 KB
testcase_19 AC 9 ms
4,348 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 25 ms
5,356 KB
testcase_24 AC 24 ms
5,356 KB
testcase_25 AC 25 ms
5,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct UnionFind {
    vector<int> rank, parent, size;

    // +1 for 1-indexed nodes
    UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) {
        iota(parent.begin(), parent.end(), 0); // parent is itself
    }
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        } else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    int getSize(int x) { return size[root(x)]; }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    UnionFind uf(n);
    vector<lint> deg(n, 0);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        uf.unite(u, v);
        deg[u]++;
        deg[v]++;
    }
    if (uf.getSize(0) == n) {
        cout << "Bob"
             << "\n";
    } else {
        bool ok = true;
        int idp = 0;
        for (int i = 0; i < n; ++i) {
            if (deg[i] == 0)
                idp++;
            else if (deg[i] != 2)
                ok = false;
        }
        if (ok && idp == 1) {
            cout << "Bob"
                 << "\n";
        } else {
            cout << "Alice"
                 << "\n";
        }
    }
    return 0;
}
0