結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
![]() |
提出日時 | 2019-09-23 20:31:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,173 bytes |
コンパイル時間 | 2,086 ms |
コンパイル使用メモリ | 201,576 KB |
最終ジャッジ日時 | 2025-01-07 19:05:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> #define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++) #define rep(i, begin, end) for(int i = int(begin); i < int(end); i++) #define all(v) v.begin(), v.end() void alice() { std::cout << "Alice" << std::endl; exit(0); } void bob() { std::cout << "Bob" << std::endl; exit(0); } int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); int n; std::cin >> n; std::vector< std::vector< int > > graph(n); loop(n - 1) { int u, v; std::cin >> u >> v; graph.at(u).emplace_back(v); graph.at(v).emplace_back(u); } auto root = -1; rep(i, 0, n) { if (!graph.at(i).empty()) { root = i; } } std::vector< int > ckd(n, false); std::queue< int > que; que.emplace(root); while(!que.empty()) { auto crr = que.front(); que.pop(); for (auto nxt : graph.at(crr)) { if (ckd.at(nxt)) continue; ckd.at(nxt) = true; que.emplace(nxt); } } auto cmp = std::accumulate(all(ckd), 0); if (cmp == n) bob(); if (cmp <= n - 2) alice(); for (auto const & v : graph) { if (!v.empty() && v.size() != 2u) alice(); } bob(); return 0; }