結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
yakki
|
| 提出日時 | 2020-01-31 21:49:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 2,000 ms |
| コード長 | 2,438 bytes |
| コンパイル時間 | 1,478 ms |
| コンパイル使用メモリ | 126,344 KB |
| 最終ジャッジ日時 | 2025-01-08 21:01:14 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
const double EPS = 1e-10;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
class DisjointSet{
public:
vector<ll> rank,p,siz;
DisjointSet(){}
DisjointSet(ll size){
rank.resize(size,0);
p.resize(size,0);
siz.resize(size,1);
rep(i,size) makeSet(i);
}
void makeSet(ll x){
p[x] = x;
rank[x] = 0;
}
bool same(ll x, ll y){
return root(x) == root(y);
}
void unite(ll x, ll y){
x = root(x);
y = root(y);
if(rank[x] > rank[y]){
siz[x] += siz[y];
p[y] = x;
}
else{
siz[y] += siz[x];
p[x] = y;
if(rank[x] == rank[y]) rank[y]++;
}
}
ll root(ll x){
if(x != p[x]){
p[x] = root(p[x]);
}
return p[x];
}
ll size(ll x){
return siz[root(x)];
}
};
int N;
vector<vector<int>> G;
int main(){
cin >> N;
G.resize(N);
DisjointSet uf(N);
rep(i,N-1){
int u,v; cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
if(!uf.same(u,v)) uf.unite(u,v);
}
vector<int> v(N);
rep(i,N){
v[i] = uf.size(i);
}
int cnt1 = 0,cnt2 = 0,cnt3 = 0;
rep(i,N){
if(v[i] == N) cnt1++;
if(v[i] == N-1) cnt2++;
if(v[i] == 1) cnt3++;
}
if(cnt1 == N) cout << "Bob" << endl;
else if(cnt2 == N-1 && cnt3 == 1){
int k1 = 0,k2 = 0;
rep(i,N){
if(G[i].size() == 2) k1++;
if(G[i].size() == 0) k2++;
}
if(k1 == N-1 && k2 == 1){
cout << "Bob" << endl;
}
else cout << "Alice" << endl;
}
else cout << "Alice" << endl;
}
yakki