結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
minato
|
| 提出日時 | 2020-02-01 13:41:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,058 bytes |
| コンパイル時間 | 2,614 ms |
| コンパイル使用メモリ | 197,480 KB |
| 実行使用メモリ | 11,300 KB |
| 最終ジャッジ日時 | 2024-09-18 19:55:56 |
| 合計ジャッジ時間 | 4,315 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 2 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////
struct UnionFind {
vector<int> node;
UnionFind() = default;
UnionFind(int x) {init(x);}
void init(int x) {
node.assign(x,-1);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (node[x] > node[y]) swap(x,y);
node[x] += node[y];
node[y] = x;
return true;
}
bool same(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
if (node[x] < 0) return x;
return node[x] = root(node[x]);
}
int size(int x) {
return -node[root(x)];
}
};
struct LowLink {
const vector<vector<int>> &G;
vector<bool> used;
vector<int> ord,low,articulation;
vector<pair<int, int>> bridge;
LowLink (const vector<vector<int>> &G) : G(G) {}
int dfs(int v, int k, int pv) {
used[v] = true;
ord[v] = k++;
low[v] = ord[v];
bool is_articulation = false;
int cnt = 0;
for (auto &nv : G[v]) {
if (!used[nv]) {
++cnt;
k = dfs(nv, k, v);
low[v] = min(low[v],low[nv]);
is_articulation |= ~pv && low[nv] >= ord[v];
if (ord[v] < low[nv]) bridge.emplace_back(minmax(v, nv));
} else if (nv != pv) {
low[v] = min(low[v],ord[nv]);
}
}
is_articulation |= pv == -1 && cnt > 1;
if (is_articulation) articulation.emplace_back(v);
return k;
}
virtual void build() {
used.assign(G.size(), false);
ord.assign(G.size(), 0);
low.assign(G.size(), 0);
int k = 0;
for (int i = 0; i < G.size(); i++) {
if (!used[i]) k = dfs(i, k, -1);
}
}
};
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N; cin >> N;
UnionFind uf(N);
vector<vector<int>> G(N);
rep(i,N-1) {
int u,v; cin >> u >> v;
uf.merge(u,v);
G[u].emplace_back(v);
G[v].emplace_back(u);
}
set<int> dic;
rep(i,N) dic.emplace(uf.root(i));
if (dic.size() == 1) {
cout << "Bob" << endl;
} else if (dic.size() >= 3) {
cout << "Alice" << endl;
} else {
LowLink LL(G);
LL.build();
cout << ((LL.bridge.size() == N-1) ? "Bob" : "Alice") << endl;
}
}
minato