結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー bachoppibachoppi
提出日時 2020-02-01 11:10:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 99,404 KB
実行使用メモリ 4,416 KB
最終ジャッジ日時 2023-10-18 23:52:58
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 8 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 29 ms
4,348 KB
testcase_21 AC 46 ms
4,348 KB
testcase_22 AC 59 ms
4,416 KB
testcase_23 AC 63 ms
4,416 KB
testcase_24 AC 61 ms
4,416 KB
testcase_25 AC 63 ms
4,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

struct UnionFind{
	vector<int> par,siz;
	UnionFind(int N): par(N), siz(N){
		rep(i, N){
			par[i] = i; siz[i] = 1;
		}
	}
	int root(int x){
		if(par[x]==x) return x;
		else return root(par[x]);
	}
	void unite(int x, int y){
		x=root(x); y=root(y);
		if(x==y) return;
		if(siz[x] < siz[y]) swap(x, y);
		par[y] = x;
		siz[x] += siz[y];
	}
	bool same(int x, int y){
		return root(x)==root(y);
	}
	int size(int x){
		return siz[root(x)];
	}
};

int main(){
  int N; cin >> N; 
  UnionFind uf(N); int cnt[N] = {};
  rep(i, N-1){
    int u, v; cin >> u >> v;
    cnt[u]++; cnt[v]++;
    uf.unite(u, v);
  }
  bool two = true;
  rep(i, N){
    if(cnt[i]!=2 && cnt[i]!=0) two=false;
  }
  bool can = false;
  if(uf.size(0)==N) can=true;
  if((uf.size(0)==N-1 || uf.size(1)==N-1) && two) can = true;
  if(can) cout << "Bob" << endl;
  else cout << "Alice" << endl;
}
    
0