結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ferinferin
提出日時 2020-01-31 21:35:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,949 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 180,528 KB
実行使用メモリ 13,712 KB
最終ジャッジ日時 2023-10-17 08:52:25
合計ジャッジ時間 3,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 6 ms
4,568 KB
testcase_14 AC 6 ms
4,552 KB
testcase_15 AC 6 ms
4,548 KB
testcase_16 AC 6 ms
4,568 KB
testcase_17 AC 6 ms
4,776 KB
testcase_18 AC 16 ms
6,428 KB
testcase_19 AC 17 ms
7,252 KB
testcase_20 AC 26 ms
7,736 KB
testcase_21 AC 40 ms
9,056 KB
testcase_22 AC 54 ms
10,904 KB
testcase_23 AC 60 ms
13,712 KB
testcase_24 AC 59 ms
13,704 KB
testcase_25 AC 60 ms
13,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

class twoEdgeComponent {
private:
    void dfs(ll v, ll p, ll &k) {
        ord[v] = k++;
        low[v] = ord[v];
        for(auto to: g[v]) {
            if(ord[to]==-1) {
                dfs(to, v, k);
                chmin(low[v], low[to]);
                if(ord[v] < low[to]) bridge.emplace_back(v, to);
            } else if(to != p) {
                chmin(low[v], ord[to]);
            }
        }
    }
    void dfs2(ll v, ll p, ll &k) {
        if(~p && ord[p] >= low[v]) cmp[v] = cmp[p];
        else cmp[v] = k++;
        for(auto to: g[v]) if(cmp[to] == -1) dfs2(to, v, k);
    }
public:
    vector<vector<ll>> g;
    vector<ll> ord, low, cmp;
    vector<PII> bridge;

    twoEdgeComponent() {}
    twoEdgeComponent(ll n) : g(n), ord(n, -1), low(n), cmp(n, -1) {}

    void add_edge(ll u, ll v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }
    ll build() {
        ll k = 0, num = 0;
        REP(i, g.size()) if(ord[i]==-1) dfs(i, -1, k), num++;
        k = 0;
        REP(i, g.size()) if(cmp[i]==-1) dfs2(i, -1, k);
        if(bridge.size()) num++;
        return num;
    }
};

int main(void) {
    ll n;
    cin >> n;
    twoEdgeComponent bcc(n);
    REP(i, n-1) {
        ll u, v;
        cin >> u >> v;
        bcc.add_edge(u, v);
    }
    ll num = bcc.build();
    
    if(num >= 3) cout << "Alice" << endl;
    else cout << "Bob" << endl;

    return 0;
}
0