結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー trineutrontrineutron
提出日時 2020-02-04 14:57:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,116 bytes
コンパイル時間 1,527 ms
コンパイル使用メモリ 174,196 KB
実行使用メモリ 814,880 KB
最終ジャッジ日時 2023-10-21 06:12:45
合計ジャッジ時間 3,306 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 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool dfs(const vector<vector<int>> &to, vector<bool> &isvisited, int index, int prev) {
    isvisited.at(index) = true;
    for (int next : to.at(index)) {
        if (next == prev) continue;
        if (isvisited.at(next)) {
            vector<bool> isvisited_new(isvisited.size());
            dfs(to, isvisited_new, next, -1);
            int period = 0;
            for (bool x : isvisited_new) {
                if (x) period++;
            }
            return period == isvisited.size() - 1;
        }
        if (dfs(to, isvisited, next, index) == false) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> to(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        to.at(u).push_back(v);
        to.at(v).push_back(u);
    }
    vector<bool> isvisited(n);
    for (int i = 0; i < n; i++) {
        if (isvisited.at(i)) continue;
        if (!dfs(to, isvisited, i, -1)) {
            cout << "Alice" << endl;
            return 0;
        }
    }
    cout << "Bob" << endl;
}
0