結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー y61mpnly61mpnl
提出日時 2020-01-31 21:58:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 177,012 KB
実行使用メモリ 10,172 KB
最終ジャッジ日時 2023-10-17 09:40:01
合計ジャッジ時間 3,061 ms
ジャッジサーバーID
(参考情報)
judge11 / 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,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 15 ms
5,420 KB
testcase_19 AC 15 ms
5,156 KB
testcase_20 AC 22 ms
6,476 KB
testcase_21 AC 33 ms
8,060 KB
testcase_22 AC 44 ms
9,380 KB
testcase_23 AC 48 ms
10,172 KB
testcase_24 AC 50 ms
10,172 KB
testcase_25 AC 46 ms
10,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using ll = long long;

int main(){
        ll n;
        scanf("%lld", &n);

        std::vector<std::vector<ll>> links(n, std::vector<ll>(0));
        for(ll i=1; i<n; i++){
                ll a, b;
                scanf("%lld %lld", &a, &b);
                links[a].push_back(b);
                links[b].push_back(a);
        }

        ll islands = 0;
        std::vector<ll> a(n, 1), landsize(0);
        for(ll i=0; i<n; i++){
                if(!a[i]) continue;
                islands++;
                ll tmp = 0;
                std::queue<ll> que;
                que.push(i);
                while(!que.empty()){
                        ll from = que.front(); que.pop();
                        a[from] = 0;
                        tmp++;
                        for(ll to: links[from]){
                                if(a[to]) que.push(to);
                        }
                }
                landsize.push_back(tmp);
        }

        ll bob = 1;
        if(islands==1) puts("Bob");
        else if(islands==2){
                ll alice = 0;
                for(std::vector<ll> l: links) alice |= (l.size()==1);
                if(alice) puts("Alice");
                else puts("Bob");
        }else puts("Alice");
        return 0;
}
0