結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー uryo1903uryo1903
提出日時 2020-01-31 22:11:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,269 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 174,464 KB
実行使用メモリ 10,832 KB
最終ジャッジ日時 2023-10-17 10:00:03
合計ジャッジ時間 3,015 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 6 ms
4,348 KB
testcase_18 AC 13 ms
5,552 KB
testcase_19 AC 13 ms
5,288 KB
testcase_20 AC 21 ms
6,608 KB
testcase_21 AC 36 ms
8,456 KB
testcase_22 AC 48 ms
10,040 KB
testcase_23 AC 53 ms
10,832 KB
testcase_24 AC 50 ms
10,832 KB
testcase_25 AC 50 ms
10,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
   
using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
   
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

struct UnionFind{
    vector<int> rank,par;
    UnionFind(int n){
        rank.resize(n,1);
        par.resize(n);
        for(int i = 0;i < n;++i){
            par[i] = i;
        }
    }
 
    int root(int node){
        if(par[node] == node) return node;
        else return (par[node] = root(par[node]));
    }
 
    bool same(int a,int b){
        return (root(a) == root(b));
    }
 
    int size(int node){
        return rank[root(node)];
    }
 
    void unite(int a,int b){
        int a_root = root(a),b_root = root(b);
        int a_size = rank[a_root],b_size = rank[b_root];
        if(a_root == b_root) return;
        if(a_size < b_size) swap(a_root,b_root);
        rank[a_root] += rank[b_root];
        par[b_root] = par[a_root];
    }
};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    UnionFind uf(n+1);
    int island = n;
    vector<vector<int> > g(n);
    rep(i,n-1){
        int u,v;
        cin >> u >> v;
        island -= (uf.root(u) != uf.root(v));
        uf.unite(u,v);
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    if(island == 1) cout << "Bob\n";
    else if(island > 2) cout << "Alice\n";
    else{
        rep(i,n){
            if(g[i].size() == 1){
                return cout << "Alice\n",0;
            }
        }
        cout << "Bob\n";
    }

    return 0;
}
0