結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー pekempeypekempey
提出日時 2020-02-14 10:40:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,114 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 83,072 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-16 00:09:58
合計ジャッジ時間 2,259 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 8 ms
5,376 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 26 ms
5,376 KB
testcase_19 AC 24 ms
5,376 KB
testcase_20 AC 41 ms
6,016 KB
testcase_21 AC 62 ms
7,296 KB
testcase_22 AC 86 ms
8,448 KB
testcase_23 AC 93 ms
8,832 KB
testcase_24 AC 92 ms
8,704 KB
testcase_25 AC 93 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    queue<int> q;
    q.push(0);
    vector<bool> visited(N);
    visited[0] = true;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : G[u]) {
            if (!visited[v]) {
                visited[v] = true;
                q.push(v);
            }
        }
    }
    if (count(visited.begin(), visited.end(), false) == 0) {
        cout << "Bob" << endl;
        return 0;
    }
    if (count(visited.begin(), visited.end(), false) == 1) {
        int zero = 0;
        int two = 0;
        for (int i = 0; i < N; i++) {
            if (G[i].size() == 0) zero++;
            if (G[i].size() == 2) two++;
        }
        if (zero == 1 && two == N - 1) {
            cout << "Bob" << endl;
            return 0;
        }
    }
    cout << "Alice" << endl;
}
0