結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー VvyLw
提出日時 2024-06-20 18:51:53
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 122,264 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-20 18:51:57
合計ジャッジ時間 3,274 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/dsu>
#include <ranges>
constexpr auto range = std::views::iota;
int main() {
    std::cin.tie(nullptr) -> sync_with_stdio(false);
    int n;
    std::cin >> n;
    atcoder::dsu uf(n);
    std::vector<int> cnt(n);
    bool gg = true;
    for(const auto i: range(0, n - 1)) {
        int u, v;
        std::cin >> u >> v;
        gg &= !uf.same(u, v);
        uf.merge(u, v);
        cnt[u]++;
        cnt[v]++;
    }
    if(gg) {
        std::cout << "Bob\n";
        std::exit(0);
    }
    if(std::ranges::any_of(cnt, [](const int x) -> bool { return x >= 1 && x != 2; })) {
        std::cout << "Alice\n";
        std::exit(0);
    }
    std::cout << (uf.size(0) == n - 1 || uf.size(1) == n - 1 ? "Bob\n" : "Alice\n");
}
0