結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー face4face4
提出日時 2020-01-31 21:59:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,187 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 83,280 KB
実行使用メモリ 5,196 KB
最終ジャッジ日時 2023-10-17 09:40:46
合計ジャッジ時間 2,240 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 19 ms
4,348 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 66 ms
5,176 KB
testcase_24 WA -
testcase_25 AC 66 ms
5,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<set>
using namespace std;

// 簡易UF
struct UF{
    vector<int> p;
    int n;

    UF(int siz){
        n = siz;
        p.resize(n, 0);
        for(int i = 0; i < n; i++)  p[i] = i;
    }

    int parent(int x){
        if(p[x] != x)   p[x] = parent(p[x]);
        return p[x];
    }

    bool same(int x, int y){
        return parent(x) == parent(y);
    }
    
    void unite(int x, int y){
        x = parent(x), y = parent(y);
        p[x] = y;
    }
};

typedef pair<int,int> pii;

int main(){
    int n;
    cin >> n;
    vector<int> deg(n, 0);
    vector<pii> vp;
    UF uf(n);
    for(int i = 0; i < n-1; i++){
        int u, v;
        cin >> u >> v;
        uf.unite(u, v);
        vp.push_back({u,v});
        deg[u]++, deg[v]++;
    }
    set<int> s;
    for(int i = 0; i < n; i++)  s.insert(uf.parent(i));
    if(s.size() > 2){
        cout << "Alice" << endl;
    }else if(s.size() == 2){
        for(int i = 0; i < n; i++){
            if(deg[i] == 0){
                cout << "Bob" << endl;
                return 0;
            }
        }
        cout << "Alice" << endl;
    }
    cout << "Bob" << endl;
    return 0;
}
0