結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
![]() |
提出日時 | 2020-01-31 21:28:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,071 bytes |
コンパイル時間 | 1,526 ms |
コンパイル使用メモリ | 171,960 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-17 07:11:57 |
合計ジャッジ時間 | 2,440 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 2 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; class UnionFind{ public: //親の番号を格納する。親だった場合は-(その集合のサイズ) vector<int> parent; UnionFind(int N){ parent = vector<int>(N,-1); } int root(int A){ if(parent[A] < 0) return A; return parent[A]=root(parent[A]); } int size(int A){ return -parent[root(A)]; } bool unite(int A, int B) { A = root(A), B = root(B); if(A == B) return false; if(size(A) < size(B)) swap(A,B); parent[A] += parent[B]; parent[B] = A; return true; } bool same(int A, int B){ return root(A)==root(B); } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll n; cin>>n; UnionFind uni(n); for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; uni.unite(a,b); } if(uni.size(0)==n){ cout << "Bob" << endl; } else cout << "Alice" << endl; }