結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
|
提出日時 | 2020-01-31 21:30:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,890 bytes |
コンパイル時間 | 1,791 ms |
コンパイル使用メモリ | 172,720 KB |
実行使用メモリ | 7,312 KB |
最終ジャッジ日時 | 2024-09-17 07:14:04 |
合計ジャッジ時間 | 3,045 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 WA * 6 |
ソースコード
/*** author: yuji9511 ***/ #include <bits/stdc++.h> using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} struct UnionFind { private: ll N; vector<ll> parent; vector<ll> num; vector<ll> diff_weight; public: UnionFind(ll n){ N = n; rep(i,0,N) parent.push_back(i); rep(i,0,N) num.push_back(1); rep(i,0,N) diff_weight.push_back(0); } ll root(ll x){ if(x == parent[x]){ return x; }else{ ll r = root(parent[x]); diff_weight[x] += diff_weight[parent[x]]; return parent[x] = r; } } void unite(ll a, ll b, ll w = 0){ w += weight(a); w -= weight(b); a = root(a); b = root(b); if(a == b) return; parent[b] = a; ll sum = num[a] + num[b]; num[a] = sum; num[b] = sum; diff_weight[b] = w; } bool same(ll a, ll b){ return root(a) == root(b);} ll sz(ll x){ return num[root(x)];} ll weight(ll x){ root(x); return diff_weight[x]; } ll diff(ll a, ll b){ return weight(b) - weight(a); } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; ll u[100010], v[100010]; UnionFind uf(100010); rep(i,0,N-1){ cin >> u[i] >> v[i]; uf.unite(u[i], v[i]); } ll max_val = 0; rep(i,0,N){ max_val = max(max_val, uf.sz(i)); } if(max_val >= N-1){ print("Bob"); }else{ print("Alice"); } }