結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
satashun
|
| 提出日時 | 2020-01-31 21:42:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 1,957 bytes |
| コンパイル時間 | 1,520 ms |
| コンパイル使用メモリ | 177,384 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 07:30:24 |
| 合計ジャッジ時間 | 2,685 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define dump(x) true
#endif
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }
template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os<<"("<<p.first<<","<<p.second<<")";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os<<"{";
rep(i, v.size()) {
if (i) os<<",";
os<<v[i];
}
os<<"}";
return os;
}
class unionfind {
vector<int> par, rank;
public:
void init(int n) {
par.resize(n);
rank.resize(n);
for (int i = 0; i < n; i++) {
par[i] = i;
rank[i] = 0;
}
}
int find(int x) {
if (par[x] == x) return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return ;
if (rank[x] < rank[y]) par[x] = y;
else {
par[y] = x;
if (rank[x] == rank[y]) ++rank[x];
}
}
bool same(int x, int y) { return (find(x) == find(y)); }
};
int main() {
int N; cin >> N;
unionfind uf;
uf.init(N);
V<int> deg(N);
rep(i, N-1) {
int a, b;
cin >> a >> b;
++deg[a]; ++deg[b];
uf.unite(a, b);
}
map<int, int> T;
rep(i, N) T[uf.find(i)]++;
if (T.size() > 2) {
puts("Alice");
} else if (T.size() == 1) {
puts("Bob");
} else {
bool one = 0;
rep(i, N) if (deg[i] == 1) {
one = 1;
}
puts(one ? "Alice" : "Bob");
}
return 0;
}
satashun