結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー kappybar
提出日時 2020-03-25 09:21:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 1,490 ms
コンパイル使用メモリ 167,392 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2025-01-01 19:56:28
合計ジャッジ時間 2,996 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 100005;
vector<vector<int>> graph(n,vector<int>());
vector<bool> visited(n,false);

void dfs(int i,int before){
    visited[i] = true;
    for(int p:graph[i]){
        if(p == before) continue;
        if(!visited[p]) dfs(p,i);
    }
}


int main() {
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int cnt = 0;
    rep(i,n){
        if(!visited[i]){
            dfs(i,-1);
            cnt ++;
        }
    }

    if(cnt == 1){
        cout << "Bob" << endl;
        return 0;
    }
    else if(cnt >= 3){
        cout << "Alice" << endl;
        return 0;
    }
    else{
        rep(i,n){
            if(graph[i].size() == 1){
                cout << "Alice" << endl;
                return 0;
            }
        }
    }

    cout << "Bob" <<endl;
    return 0;

    
}
0