結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー hig98ingrohig98ingro
提出日時 2020-01-31 22:55:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,799 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 173,344 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2023-10-17 11:40:14
合計ジャッジ時間 3,135 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,228 KB
testcase_01 AC 3 ms
6,228 KB
testcase_02 AC 3 ms
6,228 KB
testcase_03 AC 3 ms
6,232 KB
testcase_04 AC 3 ms
6,228 KB
testcase_05 AC 3 ms
6,232 KB
testcase_06 AC 3 ms
6,232 KB
testcase_07 AC 3 ms
6,232 KB
testcase_08 AC 3 ms
6,232 KB
testcase_09 AC 3 ms
6,232 KB
testcase_10 AC 3 ms
6,232 KB
testcase_11 AC 3 ms
6,232 KB
testcase_12 AC 3 ms
6,232 KB
testcase_13 AC 6 ms
6,632 KB
testcase_14 AC 6 ms
6,604 KB
testcase_15 AC 6 ms
6,604 KB
testcase_16 AC 6 ms
6,632 KB
testcase_17 AC 7 ms
6,612 KB
testcase_18 AC 15 ms
7,440 KB
testcase_19 AC 16 ms
7,748 KB
testcase_20 AC 22 ms
7,736 KB
testcase_21 AC 34 ms
8,576 KB
testcase_22 AC 49 ms
9,212 KB
testcase_23 AC 59 ms
9,868 KB
testcase_24 AC 49 ms
9,868 KB
testcase_25 AC 57 ms
9,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N;
vector<ll> uvv[101010];
ll mk[101010];
ll i, j, k,ans;
//Union木
struct UnionFind{
    vector<int> nxt;
    void init(int x){
        nxt.clear();
        nxt.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    inline void unite(int x,int y){
        nxt[find(y)] = find(x);
    }
};

ll bfs(ll a,ll p,ll s){
    //printf("%lld ", a);
    if(uvv[a].size()!=2){
        return -1;
    }
    ll i;
    fornum(i,0,uvv[a].size()){
        ll b = uvv[a][i];
        if(b==p)
            continue;
        if(b==s)
            return 1;
        ll c = bfs(b, a,s);
        if(c==-1)
            return -1;
        return c+1;
    }
    return -1;
}

int main(){
    scanf("%lld", &N);
    UnionFind uf;
    uf.init(N);
    fornum(i,1,N){
        ll u, v;
        scanf("%lld%lld", &u, &v);
        uvv[u].push_back(v);
        uvv[v].push_back(u);
        uf.unite(u, v);
    }
    ll a = 0;
    fornum(i,0,N){
        if(uf.find(i)==i){
            a++;
        }
    }
    //printf("%lld %lld %lld\n",a,b, i);
    if(a>2){
        printf("Alice");
    }else if(a==1){
        printf("Bob");
    }else{
        fornum(i,0,N){
            if(uf.find(i)==i&&uvv[i].size()>0){
                //printf("%lld\n", bfs(i, 0, i));
                if(N-1!=bfs(i,-1,i))
                    break;
            }
        }
        if(i==N){
            printf("Bob");
        }else{
            printf("Alice");
        }
    }
    

    return 0;
}
0