結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
kyort0n
|
| 提出日時 | 2020-01-31 21:33:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 1,950 bytes |
| コンパイル時間 | 1,775 ms |
| コンパイル使用メモリ | 172,400 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-17 07:18:50 |
| 合計ジャッジ時間 | 2,822 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) {
init(n);
}
void init(int n = 1) {
par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
}
else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (rank[x] < rank[y]) swap(x, y);
if (rank[x] == rank[y]) ++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x){
return Size[root(x)];
}
};
int degree[100000];
int main() {
//cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
UnionFind uni(N);
int dummy = 0;
for(int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
degree[a]++;
degree[b]++;
if(!uni.merge(a, b)) {
dummy++;
}
}
int one = 0;
for(int i = 0; i < N; i++) {
if(degree[i] == 1) one++;
}
if(dummy == 1 and one == 0) cout << "Bob" << endl;
else if(dummy == 0) cout << "Bob" << endl;
else cout << "Alice" << endl;
return 0;
}
kyort0n