結果

問題 No.977 アリス仕掛けの摩天楼
コンテスト
ユーザー 🍮かんプリン
提出日時 2020-02-01 21:56:26
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,257 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,643 ms
コンパイル使用メモリ 188,604 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2026-04-06 20:40:19
合計ジャッジ時間 4,264 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

// UnionFind
class UnionFind {
private:
    vector<int> par;
public:
    UnionFind(int n) {
        par.resize(n, -1);
    }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

vector<vector<int>> G;

int main() {
    int n; cin >> n;
    G.resize(n);
    UnionFind uf(n);
    bool ok = true;
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
        if (!uf.unite(a, b)) ok = false;
    }
    if (ok) puts("Bob");
    else {
        for (int i = 0; i < n; i++) {
            if (G[i].size() != 2 && G[i].size() != 0) {
                puts("Alice");
                return 0;
            }
        }
        puts("Bob");
    }
    return 0;
}
0