結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー rogi52rogi52
提出日時 2022-09-29 23:34:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 2,284 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 214,848 KB
実行使用メモリ 11,600 KB
最終ジャッジ日時 2023-08-24 05:11:05
合計ジャッジ時間 4,889 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 6 ms
4,968 KB
testcase_18 AC 16 ms
5,672 KB
testcase_19 AC 18 ms
8,832 KB
testcase_20 AC 28 ms
7,684 KB
testcase_21 AC 55 ms
8,272 KB
testcase_22 AC 69 ms
9,876 KB
testcase_23 AC 70 ms
11,552 KB
testcase_24 AC 65 ms
11,596 KB
testcase_25 AC 66 ms
11,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

struct LowLink {
    vector<int> used, ord, low, articulation;
    vector<pair<int,int>> bridge;

    LowLink(vector<vector<int>> &G) {
        int N = G.size(), id = 0;
        used.assign(N, 0);
        ord.assign(N, 0);
        low.assign(N, 0);
        for(int i = 0; i < N; i++)
            if(!used[i]) dfs(G, i, -1, id);
    }

    void dfs(vector<vector<int>> &G, int v, int p, int &id) {
        used[v] = 1; ord[v] = low[v] = id++;
        bool p_used = false, is_articulation = false;
        int cnt = 0;
        for(int to : G[v]) {
            if(to == p && !p_used) {
                p_used = true;
                continue;
            }
            if(!used[to]) {
                cnt++;
                dfs(G, to, v, id);
                low[v] = min(low[v], low[to]);
                if(p >= 0 && low[to] >= ord[v])
                    is_articulation = true;
                if(low[to] > ord[v])
                    bridge.push_back({v, to});
            } else {
                low[v] = min(low[v], ord[to]);
            }
        }
        if(p == -1 && cnt >= 2) is_articulation = true;
        if(is_articulation) articulation.push_back(v);
    }
};

class union_find {
  public:
    union_find(int n) : data(n, -1) {}
    int unite(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            if(size(x) < size(y)) swap(x, y);
            data[x] += data[y];
            return data[y] = x;
        }
        return -1;
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    bool same(int x, int y) { return root(x) == root(y); }

  private:
    vector<int> data;
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<vector<int>> G(N);
    union_find uf(N);
    rep(i,N-1) {
        int u,v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
        uf.unite(u, v);
    }

    set<int> st;
    rep(i,N) st.insert(uf.root(i));

    int ok1 = (LowLink(G).bridge.size() >= 1u) && (st.size() >= 2u);
    int ok2 = (st.size() >= 3);
    cout << (ok1 || ok2 ? "Alice" : "Bob") << endl;
}
0