結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー tempura_pptempura_pp
提出日時 2019-09-23 21:25:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 2,120 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 106,008 KB
実行使用メモリ 11,448 KB
最終ジャッジ日時 2023-10-19 08:18:50
合計ジャッジ時間 2,771 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 10 ms
4,348 KB
testcase_14 AC 9 ms
4,436 KB
testcase_15 AC 10 ms
4,424 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 10 ms
5,200 KB
testcase_18 AC 27 ms
5,756 KB
testcase_19 AC 32 ms
8,608 KB
testcase_20 AC 51 ms
7,816 KB
testcase_21 AC 88 ms
8,344 KB
testcase_22 AC 111 ms
9,928 KB
testcase_23 AC 115 ms
11,448 KB
testcase_24 AC 108 ms
11,432 KB
testcase_25 AC 111 ms
11,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct LowLink {
    const vector<vector<int>> &g;
    vector< int > used, ord, low;
    vector< int > articulation;
    vector< pair< int, int > > bridge;
 
    LowLink(const vector<vector<int>> &g) : g(g) {}
 
    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]);
                if(par!=-1&&low[to]>=ord[idx])is_articulation =true;
                if(ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int) to));
            }
            else if(to != par) {
                low[idx] = min(low[idx], ord[to]);
            }
        }
        if(par==-1&&cnt>1)is_articulation= true;
        if(is_articulation) articulation.push_back(idx);
        return k;
    }
 
    virtual int build() {
        used.assign(g.size(), 0);
        ord.assign(g.size(), 0);
        low.assign(g.size(), 0);
        int k = 0, c = 0;
        for(int i = 0; i < g.size(); i++) {
            if(!used[i])++c, k = dfs(i, k, -1);
        }
        return c;
    }
};


int main(){
    int n;
    cin>>n;
    vector<vector<int>> v(n);
    rep(i,n-1){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    LowLink ll(v);
    int ret = ll.build();
    if(ret>=3){
        cout<<"Alice"<<endl;
    }
    else if(ret==2&&ll.bridge.size()){
        cout<<"Alice"<<endl;
    }
    else cout<<"Bob"<<endl;
    return 0;
}
0