結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー HaaHaa
提出日時 2020-01-31 21:58:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 175,296 KB
実行使用メモリ 9,380 KB
最終ジャッジ日時 2023-10-17 09:40:11
合計ジャッジ時間 3,496 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,392 KB
testcase_01 AC 5 ms
5,392 KB
testcase_02 AC 4 ms
5,392 KB
testcase_03 AC 4 ms
5,392 KB
testcase_04 AC 4 ms
5,392 KB
testcase_05 AC 4 ms
5,392 KB
testcase_06 AC 4 ms
5,392 KB
testcase_07 AC 4 ms
5,392 KB
testcase_08 AC 4 ms
5,392 KB
testcase_09 AC 4 ms
5,392 KB
testcase_10 AC 5 ms
5,392 KB
testcase_11 AC 4 ms
5,392 KB
testcase_12 AC 4 ms
5,392 KB
testcase_13 AC 12 ms
5,948 KB
testcase_14 AC 11 ms
6,212 KB
testcase_15 AC 11 ms
6,212 KB
testcase_16 AC 11 ms
5,948 KB
testcase_17 AC 11 ms
6,476 KB
testcase_18 AC 28 ms
6,740 KB
testcase_19 AC 29 ms
8,060 KB
testcase_20 AC 42 ms
7,796 KB
testcase_21 AC 68 ms
8,060 KB
testcase_22 AC 86 ms
8,588 KB
testcase_23 AC 106 ms
9,380 KB
testcase_24 AC 103 ms
9,380 KB
testcase_25 AC 106 ms
9,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

VVI edge(100001, VI(0));
vector<bool> f(100001, 0);
bool ff = 0;

void dfs(int v) {
	f[v] = 1;
	if (edge[v].size() != 2)
		ff = 1;
	for (int i = 0; i < edge[v].size(); i++) {
		if (!f[edge[v][i]]) {
			dfs(edge[v][i]);
		}
	}
}

void dfs2(int v) {
	f[v] = 1;
	if (edge[v].size() != 2)
		ff = 1;
	for (int i = 0; i < edge[v].size(); i++) {
		if (!f[edge[v][i]]) {
			dfs(edge[v][i]);
		}
	}
}

int main() {
	int n; cin >> n;
	int a, b;
	REP(i, n - 1) {
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	ff = 0;
	dfs(0);
	if (!ff) {
		int c = 0;
		REP(i, n) {
			if (!f[i]) {
				c++;
			}
		}
		if (c == 1) {
			cout << "Bob" << endl;
		}
		else {
			cout << "Alice" << endl;
		}
		return 0;
	}
	REP(i, n) f[i] = 0;
	ff = 0;
	dfs2(1);
	if (!ff) {
		cout << "Bob" << endl;
	}
	else {
		REP(i, n) {
			if (!f[i]) {
				cout << "Alice" << endl;
				return 0;
			}
		}
		cout << "Bob" << endl;
	}
	return 0;
}
0