結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー furafura
提出日時 2020-02-01 00:07:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 169,476 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:01:04
合計ジャッジ時間 3,443 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 4 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 8 ms
4,348 KB
testcase_19 AC 8 ms
4,348 KB
testcase_20 AC 12 ms
4,348 KB
testcase_21 AC 18 ms
4,348 KB
testcase_22 AC 22 ms
4,348 KB
testcase_23 AC 24 ms
4,348 KB
testcase_24 AC 23 ms
4,348 KB
testcase_25 AC 24 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){
			if(p[v]<p[u]) swap(u,v);
			p[u]+=p[v]; p[v]=u; n--;
		}
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size()const{ return n; }
	int size(int u){ return -p[find(u)]; }
};

int main(){
	int n; scanf("%d",&n);
	union_find U(n);
	vector<int> deg(n);
	rep(i,n-1){
		int u,v; scanf("%d%d",&u,&v);
		U.unite(u,v);
		deg[u]++;
		deg[v]++;
	}

	puts(U.size()==1||(U.size()==2&&count(deg.begin(),deg.end(),2)==n-1)?"Bob":"Alice");

	return 0;
}
0