結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー QCFiumQCFium
提出日時 2020-01-31 22:05:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 178,460 KB
実行使用メモリ 9,676 KB
最終ジャッジ日時 2023-10-17 09:52:13
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 6 ms
4,908 KB
testcase_18 AC 13 ms
5,188 KB
testcase_19 AC 14 ms
7,564 KB
testcase_20 AC 22 ms
7,300 KB
testcase_21 AC 33 ms
8,092 KB
testcase_22 AC 40 ms
9,412 KB
testcase_23 AC 43 ms
9,676 KB
testcase_24 AC 41 ms
9,676 KB
testcase_25 AC 43 ms
9,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::vector<std::vector<int> > hen;

std::vector<bool> used;
std::vector<int> ord, low;
int tour_cnt = 0;
bool bridge = false;
void dfs(int i, int prev) {
	ord[i] = tour_cnt++;
	low[i] = i;
	for (auto j : hen[i]) {
		if (j == prev) continue;
		if (used[j]) {
			low[i] = std::min(low[i], j);
		} else {
			used[j] = true;
			dfs(j, i);
			low[i] = std::min(low[i], low[j]);
			if (low[j] > ord[i]) bridge = true;
		}
	}
}

int main() {
	int n = ri();
	hen.resize(n);
	for (int i = 0; i + 1 < n; i++) {
		int a = ri();
		int b = ri();
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	used.resize(n);
	ord.resize(n);
	low.resize(n);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (!used[i]) {
			used[i] = true;
			cnt++;
			dfs(i, -1);
		}
	}
	bool res = cnt > 2 || (cnt == 2 && bridge);
	puts(res ? "Alice" : "Bob");
  	return 0;
}
0