結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー bal4ubal4u
提出日時 2020-02-24 09:35:28
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,138 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 03:12:52
合計ジャッジ時間 1,793 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 0 ms
6,944 KB
testcase_10 AC 0 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 5 ms
6,944 KB
testcase_22 AC 7 ms
6,940 KB
testcase_23 AC 8 ms
6,948 KB
testcase_24 AC 7 ms
6,944 KB
testcase_25 AC 8 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yuki 977 アリス仕掛けの摩天楼
// 2020.2.24 bal4u

#include <stdio.h>

int getchar_unlocked(void);
#define gc() getchar_unlocked()

int in() {  // 整数の入力
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX 100005

/* UNION-FIND library */
int id[MAX], size[MAX];
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q) {
    int i = root(p), j = root(q); if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}

int hi[MAX];
int main()
{
	int i, a, b, n, N;
	static char *ans[] = { "Alice", "Bob" };

	N = in();
	init(N);
	for (i = 1; i < N; ++i) {
		a = in(), b = in();
		hi[a]++, hi[b]++;
		unite(a, b);
	}
	a = 0;
	n = size[root(0)];
	if (n == 1) n = size[root(1)];
	if (n == N) a = 1;
	else if (n == N-1) {
		for (i = 0; i < N; ++i) {
			if (hi[i] == 1) break;
		}
		if (i == N) a = 1;
	}
	puts(ans[a]);
	return 0;
}
0