結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー face4face4
提出日時 2020-01-31 22:46:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 1,738 ms
コンパイル使用メモリ 80,340 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 11:23:35
合計ジャッジ時間 2,231 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 7 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 31 ms
4,348 KB
testcase_21 AC 50 ms
4,348 KB
testcase_22 AC 62 ms
4,348 KB
testcase_23 AC 63 ms
4,348 KB
testcase_24 AC 62 ms
4,348 KB
testcase_25 AC 64 ms
4,348 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;
    }
};

int main(){
    int n;
    cin >> n;
    UF uf(n);
    vector<int> deg(n, 0);
    for(int i = 0; i < n-1; i++){
        int u, v;
        cin >> u >> v;
        deg[u]++, deg[v]++;
        uf.unite(u, v);
    }
    set<int> s;
    for(int i = 0; i < n; i++)  s.insert(uf.parent(i));
    int comp = s.size();
    bool able = false;
    for(int i = 0; i < n; i++)  able |= deg[i]==1;
    if(able)    comp++;
    comp--;
    cout << (comp == 1 ? "Bob" : "Alice") << endl;
    return 0;
}
0