結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー leaf_1415leaf_1415
提出日時 2020-01-31 21:36:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,294 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 72,280 KB
実行使用メモリ 9,632 KB
最終ジャッジ日時 2023-10-17 08:53:14
合計ジャッジ時間 2,468 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,984 KB
testcase_01 AC 4 ms
5,984 KB
testcase_02 AC 4 ms
5,984 KB
testcase_03 AC 4 ms
5,988 KB
testcase_04 AC 4 ms
5,988 KB
testcase_05 AC 4 ms
5,988 KB
testcase_06 AC 4 ms
5,988 KB
testcase_07 AC 4 ms
5,992 KB
testcase_08 AC 4 ms
5,992 KB
testcase_09 AC 4 ms
5,992 KB
testcase_10 AC 3 ms
5,992 KB
testcase_11 AC 4 ms
5,992 KB
testcase_12 AC 4 ms
5,992 KB
testcase_13 AC 8 ms
6,356 KB
testcase_14 AC 7 ms
6,404 KB
testcase_15 AC 7 ms
6,404 KB
testcase_16 AC 7 ms
6,352 KB
testcase_17 AC 7 ms
6,336 KB
testcase_18 AC 14 ms
7,128 KB
testcase_19 AC 15 ms
6,928 KB
testcase_20 AC 24 ms
7,496 KB
testcase_21 AC 40 ms
8,372 KB
testcase_22 AC 52 ms
8,976 KB
testcase_23 AC 53 ms
9,628 KB
testcase_24 AC 46 ms
9,628 KB
testcase_25 AC 52 ms
9,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#define llint long long

using namespace std;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n;
vector<llint> G[100005];
UnionFind uf(100005);
set<llint> S;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		u++, v++;
		G[u].push_back(v);
		G[v].push_back(u);
		uf.unite(u, v);
	}
	for(int i = 1; i <= n; i++) S.insert(uf.root(i));
	
	if(S.size() >= 3){
		cout << "Alice" << endl;
		return 0;
	}
	if(S.size() == 1){
		cout << "Bob" << endl;
		return 0;
	}
	
	bool flag0 = false, flag2 = true;
	for(int i = 1; i <= n; i++){
		if(G[i].size() != 2){
			if(G[i].size() == 0) flag0 = true;
			else flag2 = false;
		}
	}
	if(flag0 && flag2) cout << "Bob" << endl;
	else cout << "Alice" << endl;
	
	return 0;
}
0