結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2020-02-01 04:56:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,159 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 171,396 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-10-18 23:31:41
合計ジャッジ時間 3,039 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 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 7 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 20 ms
4,348 KB
testcase_20 AC 30 ms
4,348 KB
testcase_21 AC 46 ms
4,348 KB
testcase_22 AC 59 ms
4,388 KB
testcase_23 AC 62 ms
4,388 KB
testcase_24 AC 63 ms
4,388 KB
testcase_25 AC 62 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct UnionFind {
	const int V;
	// par[x] := xのroot
	vector<int> par;
	// sz[x] := xを含む集合のサイズ
	vector<int> sz;
	UnionFind(const int V) :
		V(V),
		par(vector<int>(V)),
		sz(vector<int>(V, 1))
		{
			for(int i = 0; i < V; ++i) par[i] = i;
		}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(same(x, y)) return false;
		if(y < x) swap(x, y);
		par[y] = x;
		sz[x] += sz[y];
		return true;
	}
	int root(int x) {
		if(par[x] == x) return x;
		return (par[x] = root(par[x]));
	}
	bool same(int x, int y) {
		return (root(x) == root(y));
	}
	int size(int x) {
		return sz[root(x)];
	}
};


int main() {
	int n; cin >> n;
	UnionFind uf(n);
	int deg[n] = {};
	for(int i = 0; i < n - 1; ++i) {
		int u, v; cin >> u >> v;
		++deg[u];
		++deg[v];
		uf.unite(u, v);
	}
	int e = 0;
	for(int i = 0; i < n; ++i) {
		if(i == uf.root(i)) {
			++e;
		}
	}
	string ans;
	if(e == 1) {
		ans = "Bob";
	} else if(e >= 3) {
		ans = "Alice";
	} else {
		ans = "Bob";
		for(int i = 0; i < n; ++i) {
			if(deg[i] != 0 and deg[i] != 2) {
				ans = "Alice";
			}
		}
	}
	cout << ans << '\n';
	return 0;
}
0