結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー QCFium
提出日時 2020-01-31 22:05:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 179,428 KB
実行使用メモリ 9,700 KB
最終ジャッジ日時 2024-09-17 08:19:56
合計ジャッジ時間 3,232 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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