結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー | kcvlex |
提出日時 | 2020-02-02 01:33:35 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 4,395 bytes |
コンパイル時間 | 1,976 ms |
コンパイル使用メモリ | 182,768 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-09-18 20:26:38 |
合計ジャッジ時間 | 3,201 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 2 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 | 6 ms
5,376 KB |
testcase_14 | AC | 6 ms
5,376 KB |
testcase_15 | AC | 6 ms
5,376 KB |
testcase_16 | AC | 6 ms
5,376 KB |
testcase_17 | AC | 7 ms
5,680 KB |
testcase_18 | AC | 17 ms
6,144 KB |
testcase_19 | AC | 20 ms
9,856 KB |
testcase_20 | AC | 24 ms
6,656 KB |
testcase_21 | AC | 41 ms
8,576 KB |
testcase_22 | AC | 55 ms
9,984 KB |
testcase_23 | AC | 55 ms
10,752 KB |
testcase_24 | AC | 68 ms
12,416 KB |
testcase_25 | AC | 54 ms
10,624 KB |
ソースコード
// #define DEBUGGING #include <bits/stdc++.h> #define endl '\n' #define ALL(V) (V).begin(), (V).end() #define ALLR(V) (V).rbegin(), (V).rend() using ll = std::int64_t; using ull = std::uint64_t; using PLL = std::pair<ll, ll>; using TLL = std::tuple<ll, ll, ll>; template <typename T> using V = std::vector<T>; template <typename T> using VV = V<V<T>>; template <typename T> const T& var_min(const T &t) { return t; } template <typename T> const T& var_max(const T &t) { return t; } template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); } template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); } namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } #define mv_rec make_v(init, tail...) template <typename T> T make_v(T init) { return init; } template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); } #undef mv_rec using namespace std; #ifdef DEBUGGING #include "../../debug/debug.cpp" #else #define DEBUG(...) 0 #define DEBUG_SEPARATOR_LINE 0 #endif struct LowLink { ll N; const VV<ll> &edges; V<ll> low, ord; V<bool> visited; V<bool> is_articulation; ll dfs_counter; LowLink(const VV<ll> &edges) : N(edges.size()), edges(edges), low(edges.size()), ord(edges.size()), visited(edges.size()), is_articulation(edges.size()), dfs_counter(0) { for (ll i = 0; i < N; i++) if (!visited[i]) dfs(i, -1); } void dfs(ll cur, ll pre) { visited[cur] = true; ord[cur] = dfs_counter++; low[cur] = ord[cur]; ll children = 0; bool art = false; for (ll nxt : edges[cur]) { if (!visited[nxt]) { children++; dfs(nxt, cur); chmin(low[cur], low[nxt]); art |= (pre == -1 ? 2 <= children : ord[cur] <= low[nxt]); } else if (nxt != pre) { chmin(low[cur], ord[nxt]); } } is_articulation[cur] = art; } bool is_art(ll cur) { return is_articulation[cur]; } // u -> v bool is_bridge(ll from, ll to) { return ord[from] < low[to]; } V<PLL> enum_bridges() { V<PLL> ret; for (ll from = 0; from < N; from++) { for (ll to : edges[from]) { if (!(from < to)) continue; if (is_bridge(from, to)) ret.emplace_back(from, to); } } return ret; } }; struct UnionFind { V<ll> rank; V<ll> parent; UnionFind(ll N) : rank(N, 0), parent(N) { iota(parent.begin(), parent.end(), 0ll); } ll find(ll child) { return (child == parent[child] ? child : parent[child] = find(parent[child])); } void unit(ll x, ll y) { ll px = find(x); ll py = find(y); if(px == py) { return; } if(rank[px] < rank[py]) { swap(px, py); } parent[py] = px; rank[px] += (rank[px] == rank[py]); } bool same(ll x, ll y) { return (find(x) == find(y)); } }; bool solve() { ll N; cin >> N; VV<ll> edges(N); UnionFind uf(N); for (ll i = 1; i < N; i++) { ll u, v; cin >> u >> v; uf.unit(u, v); edges[u].push_back(v); edges[v].push_back(u); } set<ll> pset; for (ll i = 0; i < N; i++) pset.insert(uf.find(i)); if (pset.size() == 1) return true; if (3 <= pset.size()) return false; LowLink low(edges); for (ll i = 0; i < N; i++) for (ll j : edges[i]) if (low.is_bridge(i, j)) return false; return true; } int main() { cout << (!solve() ? "Alice" : "Bob") << endl; return 0; }