結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー kyoprounokyoprouno
提出日時 2020-03-11 23:28:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,280 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 188,720 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-27 21:49:41
合計ジャッジ時間 3,143 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 7 ms
6,940 KB
testcase_14 AC 6 ms
6,940 KB
testcase_15 AC 7 ms
6,940 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 17 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 29 ms
6,944 KB
testcase_21 AC 47 ms
6,940 KB
testcase_22 AC 58 ms
6,940 KB
testcase_23 AC 57 ms
7,168 KB
testcase_24 AC 56 ms
7,168 KB
testcase_25 AC 56 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=998244353;

class DisjointSet{
    public:
    vector<ll> rank,p;
    DisjointSet(){}
    DisjointSet(ll size){ //作られうる木の頂点数の最大値を入れる。
        rank.resize(size,0);
        p.resize(size,0);
        rep(i,size) makeSet(i);
    }
    void makeSet(ll x){ //xだけが属する木を作る。
        p[x]=x;
        rank[x]=0;
    }
    bool same(ll x,ll y){ //xとyが同じ木に属するかどうか
        return findSet(x)==findSet(y);
    }
    void unite(ll x, ll y){
        link(findSet(x),findSet(y));
    }
    void link(ll x, ll y){ //rankが大きい方の根に小さい方の根をつける。
        if(rank[x]>rank[y]){
            p[y]=x;
        }
        else{
            p[x]=y;
            if(rank[x]==rank[y]){
                rank[y]++; //xとyの木のrankが同じであれば、統合するとrankが1増える。
            }
        }
    }
    ll findSet(ll x){ //xが属する木の根の番号を返す
        if(x!=p[x]){
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};



int main()
{
    ll n;
    cin >> n;
    if(n==2){
        cout << "Bob" << endl;
        return 0;
    }
    vector<ll> u(n-1);
    vector<ll> v(n-1);
    vector<ll> cnt(n,0);
    bool flag=false;
    DisjointSet ds=DisjointSet(n);
    rep(i,n-1){
        cin >> u[i] >> v[i];
        if(ds.same(u[i],v[i])){
            flag=true;
        }
        else{
            flag=false;
        }
        ds.unite(u[i],v[i]);
    }
    set<ll> s;
    rep(i,n){
        s.insert(ds.findSet(i));
    }
    ll w=s.size();
    if(w==1){
        cout << "Bob" << endl;
    }
    else if(w>=2){
        cout << "Alice" << endl;
    }
    else{
        if(!flag) cout << "Bob" << endl;
        else cout << "Alice" <<endl;
    }
    return 0;
} 
0