結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー RyumaRyamaRyumaRyama
提出日時 2020-01-31 22:24:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 75,404 KB
実行使用メモリ 9,436 KB
最終ジャッジ日時 2023-10-17 10:28:01
合計ジャッジ時間 2,500 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 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 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 9 ms
4,684 KB
testcase_18 AC 24 ms
5,212 KB
testcase_19 AC 25 ms
7,060 KB
testcase_20 AC 39 ms
6,808 KB
testcase_21 AC 61 ms
7,852 KB
testcase_22 AC 78 ms
9,172 KB
testcase_23 AC 81 ms
9,436 KB
testcase_24 AC 82 ms
9,436 KB
testcase_25 AC 81 ms
9,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

void dfs(vector<bool>& checked, vector<vector<int>>& path, int island) {
    checked[island] = true;
    for (auto i : path[island]) {
        if (!checked[i]) dfs(checked, path, i);
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> path(n, vector<int>());
    vector<bool> checked(n, false);
    vector<int> path_cnt(n, 0);
    for (int i=0; i<n-1; i++) {
        int u, v;
        cin >> u >> v;
        path[u].push_back(v);
        path_cnt[u]++;
        path[v].push_back(u);
        path_cnt[v]++;
    }

    int cnt = 0;
    bool f = false;
    for (int i=0; i<n; i++) {
        if (!checked[i]) {
            cnt++;
            dfs(checked, path, i);
        }
        if (path_cnt[i] == 1) f = true;
    }

    if (cnt > 2 || (cnt == 2 && f))
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;
}
0