結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー けーむけーむ
提出日時 2020-06-18 17:40:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 2,730 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 180,648 KB
実行使用メモリ 13,100 KB
最終ジャッジ日時 2023-09-16 12:11:08
合計ジャッジ時間 3,062 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,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 6 ms
4,392 KB
testcase_17 AC 6 ms
5,088 KB
testcase_18 AC 16 ms
6,076 KB
testcase_19 AC 19 ms
8,680 KB
testcase_20 AC 20 ms
6,408 KB
testcase_21 AC 28 ms
7,732 KB
testcase_22 AC 37 ms
9,032 KB
testcase_23 AC 43 ms
9,788 KB
testcase_24 AC 55 ms
13,100 KB
testcase_25 AC 45 ms
9,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<typename T>
struct LowLink {
private:
    const vector<vector<T>> &g;
    vector<int> used, ord, low;
    
    int dfs(int idx, int k, int par) {
        used[idx] = true;
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_articulation = false;
        int cnt = 0;
        for(auto &to : g[idx]) {
            if (!used[to]) {
                ++cnt;
                k = dfs(to, k, idx);
                low[idx] = min(low[idx], low[to]);
                is_articulation |= ~par && low[to] >= ord[idx];
                if (ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int)to));
            }
            else if (to != par) {
                low[idx] = min(low[idx], ord[to]);
            }
        }
        is_articulation |= par == -1 && cnt > 1;
        if (is_articulation) articulation.push_back(idx);
        return k;
    }
    
public:
    vector<int> articulation;
    vector<pair<int, int>> bridge;
    
    LowLink(const vector<vector<T>> &g) : g(g) {}
    
    void build() {
        used.assign(g.size(), 0);
        ord.assign(g.size(), 0);
        low.assign(g.size(), 0);
        int k = 0;
        for(int i = 0; i < g.size(); i++) {
            if (!used[i]) k = dfs(i, k, -1);
        }
    }
};

ll n;
vector<vector<ll>> g;
vector<ll> used;

void dfs(ll v, ll p = -1) {
    used[v] = 1;
    for(auto u : g[v]) {
        if (u == p) continue;
        if (used[u]) continue;
        dfs(u, v);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n;
    g.resize(n);
    rep(i, n - 1) {
        ll u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    used.resize(n, 0);
    dfs(0);
    if (accumulate(all(used), 0LL) == n) {
        cout << "Bob" << endl;
        return 0;
    }
    rep(i, n) {
        if (used[i]) continue;
        dfs(i);
        break;
    }
    if (accumulate(all(used), 0LL) != n) {
        cout << "Alice" << endl;
        return 0;
    }
    LowLink<ll> link(g);
    link.build();
    auto bridge = link.bridge;
    if (sz(bridge) > 0) {
        cout << "Alice" << endl;
    }
    else {
        cout << "Bob" << endl;
    }
    return 0;
}
0