結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ShibuyapShibuyap
提出日時 2020-02-22 12:37:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,516 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 166,272 KB
実行使用メモリ 13,000 KB
最終ジャッジ日時 2024-04-17 22:14:39
合計ジャッジ時間 3,879 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,856 KB
testcase_01 AC 6 ms
9,856 KB
testcase_02 AC 7 ms
9,856 KB
testcase_03 AC 7 ms
9,824 KB
testcase_04 AC 7 ms
9,972 KB
testcase_05 AC 7 ms
9,856 KB
testcase_06 AC 7 ms
9,856 KB
testcase_07 AC 7 ms
9,668 KB
testcase_08 AC 6 ms
9,856 KB
testcase_09 AC 7 ms
9,856 KB
testcase_10 AC 7 ms
9,856 KB
testcase_11 AC 7 ms
9,856 KB
testcase_12 AC 7 ms
9,856 KB
testcase_13 AC 14 ms
9,984 KB
testcase_14 AC 13 ms
9,984 KB
testcase_15 AC 14 ms
10,152 KB
testcase_16 AC 14 ms
10,112 KB
testcase_17 AC 14 ms
10,128 KB
testcase_18 AC 30 ms
10,752 KB
testcase_19 AC 33 ms
10,848 KB
testcase_20 AC 51 ms
11,392 KB
testcase_21 AC 80 ms
12,160 KB
testcase_22 AC 98 ms
12,716 KB
testcase_23 AC 103 ms
12,860 KB
testcase_24 AC 95 ms
12,992 KB
testcase_25 AC 103 ms
13,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Alice");}else{puts("Bob");}
#define MAX_N 200005
int par[MAX_N]; // 親
int rank_[MAX_N]; // 木の深さ

// n要素で初期化
void UFinit(){
    for(int i=0;i<MAX_N;i++){
        par[i] = i;
        rank_[i] = 0;
    }
}

// 木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank_[x] < rank_[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rank_[x] == rank_[y]) rank_[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}


vector<int> G[MAX_N];

int main() {
    int n;
    cin >> n;

    UFinit();

    int cnt = n;

    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
        if(same(a, b)){
            ;
        }else{
            cnt--;
        }
        unite(a, b);
    }

    int flag = 0;
    if(cnt >= 3){
        flag = 1;
    }else if(cnt == 1){
        ;
    }else{
        rep(i,n){
            if(G[i].size() == 1)flag = 1;
        }
    }

    if(flag)yn;
    
    return 0;
}
 
 
0