結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー trineutrontrineutron
提出日時 2020-02-04 14:39:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 2,645 ms
コンパイル使用メモリ 173,352 KB
実行使用メモリ 8,900 KB
最終ジャッジ日時 2023-10-21 06:12:14
合計ジャッジ時間 3,605 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 9 ms
4,348 KB
testcase_14 WA -
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 11 ms
4,800 KB
testcase_18 AC 26 ms
4,940 KB
testcase_19 AC 32 ms
7,316 KB
testcase_20 AC 47 ms
6,788 KB
testcase_21 AC 68 ms
7,580 KB
testcase_22 AC 89 ms
8,636 KB
testcase_23 AC 108 ms
8,900 KB
testcase_24 AC 95 ms
8,900 KB
testcase_25 AC 108 ms
8,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool dfs(const vector<vector<int>> &to, vector<bool> &isvisited, int index, int prev) {
    for (int next : to.at(index)) {
        if (next == prev) continue;
        if (isvisited.at(next)) {
            int period = 0;
            for (auto x : isvisited) {
                if (x) period++;
            }
            if (period != isvisited.size() - 1) {
                return false;
            } else {
                continue;
            }
        }
        isvisited.at(next) = true;
        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);
    if (dfs(to, isvisited, 0, -1)) {
        cout << "Bob" << endl;
    } else {
        cout << "Alice" << endl;
    }
}
0