結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー granddaifukugranddaifuku
提出日時 2020-06-12 15:38:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,877 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 170,392 KB
実行使用メモリ 4,772 KB
最終ジャッジ日時 2023-09-06 09:15:32
合計ジャッジ時間 4,203 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 12 ms
4,380 KB
testcase_21 AC 18 ms
4,376 KB
testcase_22 AC 24 ms
4,772 KB
testcase_23 AC 24 ms
4,612 KB
testcase_24 AC 23 ms
4,532 KB
testcase_25 AC 24 ms
4,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long ;
using ld = long double;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

class DisjointSet {
    public:
        vector<int> rank, p, size;

        DisjointSet() {}
        DisjointSet(int s) {
            rank.resize(s, 0);
            p.resize(s, 0);
            size.resize(s, 0);
            rep (i, s) init(i);
        }

        void init(int x) {
            p[x] = x;
            rank[x] = 0;
            size[x] = 1;
        }

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

        void makeSet(int x, int y) {
            if (isSame(x, y)) return;
            link(root(x), root(y));
        }

        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
                size[x] += size[y];
            } else {
                p[x] = y;
                size[y] += size[x];
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }

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

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    DisjointSet dj = DisjointSet(n);
    rep (i, n - 1) {
        int u, v;
        cin >> u >> v;
        dj.makeSet(u, v);
    }
    vector<int> p(n);
    rep (i, n) p[dj.root(i)]++;
    int mx = 0;
    rep (i, n) mx = max(mx, p[i]);
    if (n - mx >= 1) cout << "Alice" << endl;
    else cout << "Bob" << endl;
    
    return 0;
}

0