結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-01-31 22:18:47
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,862 bytes
コンパイル時間 1,112 ms
コンパイル使用メモリ 141,080 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2024-05-07 20:20:15
合計ジャッジ時間 2,140 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 11 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 16 ms
6,144 KB
testcase_21 AC 24 ms
7,936 KB
testcase_22 AC 30 ms
9,088 KB
testcase_23 WA -
testcase_24 AC 38 ms
9,984 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;
using P = pair<int,int>;

vector<int64> bfs(const vector<vector<int64>>& g) {
    int n = g.size();
    vector<int64> ans(n, -1);
    queue<P> q;
    q.emplace(0,0);

    while(!q.empty()) {
        auto [u, ni] = q.front(); q.pop();
        if (u == 0 && ni == n-1) {
            ans[0] = n-1;
            return ans;
        }
        if (ans[u] != -1) continue;
        ans[u] = ni;
        for (auto v : g[u]) {
            if (ni==n-1 && v == 0) ans[0] = n-1;
            else {
                q.emplace(v, ni+1);
            }
        }
    }
    return ans;
}

//void dfs(int64 u, int p,  int64 n, const vector<vector<int64>>& g, vector<bool>& visited, vector<int64>& path) {
//
//    if (visited[u]) return;
//
//    for(const auto& v : g[u]) {
//        if (v == p) continue;
//        dfs(v, u, n+1, g, visited, path);
//    }
//}

int main() {
    int64 n;
    cin >> n;
    vector<vector<int64>> g(n);

    if (n == 2) {
        cout << "Bob" << endl;
        return 0;
    }

    for (int i = 0; i < n - 1; i++) {
        int64 u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<int64> v = bfs(g);
    bool ans = v[0] == n-1;
    ans = ans || any_of(v.begin(), v.end(), [&](int x){return x==n-1;});



    cout << (ans? "Bob" : "Alice") << endl;
}
0