結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
|
| 提出日時 | 2020-03-12 01:06:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 3,102 bytes |
| コンパイル時間 | 1,245 ms |
| コンパイル使用メモリ | 119,280 KB |
| 実行使用メモリ | 11,436 KB |
| 最終ジャッジ日時 | 2024-11-16 04:29:57 |
| 合計ジャッジ時間 | 2,645 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932; // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;
// constexpr int mod = 998244353;
template<typename G>
struct LowLink{
const G& g;
vector<int> visited, order, low;
vector<int> articulation; // 関節点
vector<pair<int, int>> bridge; // 橋 (order[from] < low[to])
int LinkSize = 0;
LowLink(const G &g) : g(g) {}
int dfs(int from, int k, int par = -1){
visited[from] = true;
order[from] = k++;
low[from] = order[from];
bool is_articulation = false;
int cnt = 0;
for(auto &to : g[from]){
if(!visited[to]){
++cnt;
k = dfs(to, k, from);
low[from] = min(low[from], low[to]);
// 頂点 from がDFS木の根以外であるときの関節点となる条件
is_articulation |= ~par && low[to] >= order[from];
// (from, to) が条件を満たせば、橋に追加
if(order[from] < low[to]) bridge.emplace_back(minmax(from, (int)to));
}
else if(to != par){
low[from] = min(low[from], order[to]);
}
}
// 頂点 from がDFS木の根であるときの関節点となる条件
is_articulation |= par == -1 && cnt > 1;
if(is_articulation) articulation.push_back(from);
return k;
}
virtual void build(){
visited.assign(g.size(), 0);
order.assign(g.size(), 0);
low.assign(g.size(), 0);
int k = 0;
for(int i = 0; i < g.size(); ++i){
if(!visited[i]) k = dfs(i, k), ++LinkSize;
}
}
};
using G = vector<vector<int>>;
G graph;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
graph.resize(n);
for(int i = 0; i < n - 1; ++i){
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
LowLink<G> lowlink(graph);
lowlink.build();
int LinkSize = lowlink.LinkSize;
if(LinkSize == 1){
puts("Bob");
return 0;
}
if(LinkSize >= 3){
puts("Alice");
return 0;
}
int BridgeSize = lowlink.bridge.size();
if(BridgeSize == 0) puts("Bob");
else puts("Alice");
}