結果
問題 | No.977 アリス仕掛けの摩天楼 |
ユーザー |
![]() |
提出日時 | 2020-03-20 16:06:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 2,087 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 176,136 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-14 08:05:54 |
合計ジャッジ時間 | 3,112 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() const ll MOD = 1000000007ll; #define FIX(a) ((a)%MOD+MOD)%MOD template<typename T> class UnionFind { vector<T> parent; vector<T> rank; public: UnionFind(T n) { init(n); } void init(T n) { parent.clear(); rank.clear(); for(int i=0; i<n; i++){ parent.emplace_back(i); rank.emplace_back(0); } } int find(T x){ if(parent[x] == x) return x; else return parent[x] = find(parent[x]); } void unite(T x, T y){ x = find(x); y = find(y); if(x==y) return; if(rank[x] < rank[y]){ parent[x] = y; } else { parent[y] = x; if(rank[x] == rank[y]) rank[x]++; } } bool same(T x, T y){ return find(x) == find(y); } }; const int N = 10e4+5; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; int bridges[N]={}; UnionFind<int> uf(n); REP(i,n-1){ int u,v; cin>>u>>v; bridges[u]++; bridges[v]++; uf.unite(u,v); } int cntr = 0; vi roots; FOR(i,0,n){ roots.emplace_back(uf.find(i)); if(bridges[i]==1) cntr=1; } //DEBUG_VEC(roots); sort(ALL(roots)); roots.erase(unique(ALL(roots)), roots.end()); //DEBUG_VEC(roots); cntr += roots.size(); if(cntr>=3) cout << "Alice" << endl; else cout << "Bob" << endl; return 0; }