結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー chinchillachinchilla
提出日時 2020-02-02 14:40:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 356 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 11,980 KB
実行使用メモリ 28,180 KB
最終ジャッジ日時 2023-10-19 00:50:34
合計ジャッジ時間 4,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,160 KB
testcase_01 AC 29 ms
10,160 KB
testcase_02 AC 28 ms
10,160 KB
testcase_03 AC 29 ms
10,160 KB
testcase_04 AC 28 ms
10,160 KB
testcase_05 AC 29 ms
10,160 KB
testcase_06 AC 29 ms
10,160 KB
testcase_07 AC 29 ms
10,164 KB
testcase_08 AC 29 ms
10,164 KB
testcase_09 AC 29 ms
10,164 KB
testcase_10 AC 30 ms
10,164 KB
testcase_11 AC 30 ms
10,164 KB
testcase_12 AC 30 ms
10,164 KB
testcase_13 AC 68 ms
11,820 KB
testcase_14 AC 57 ms
11,820 KB
testcase_15 AC 59 ms
11,820 KB
testcase_16 AC 67 ms
11,816 KB
testcase_17 AC 66 ms
11,820 KB
testcase_18 AC 148 ms
15,500 KB
testcase_19 AC 151 ms
15,504 KB
testcase_20 AC 229 ms
18,728 KB
testcase_21 AC 343 ms
23,688 KB
testcase_22 AC 448 ms
27,388 KB
testcase_23 AC 546 ms
28,180 KB
testcase_24 AC 442 ms
28,176 KB
testcase_25 AC 540 ms
28,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
b = [tuple(map(int, input().split())) for _ in range(n-1)]
l = list(range(n))
def f(u, d = 0): return (u, d) if l[u] == u else f(l[u], d+1)
c = [0] * n
r = n - 1
for u, v in b:
	c[u] += 1
	c[v] += 1
	u, d = f(u)
	v, e = f(v)
	if u == v: break
	if d < e: l[u] = v
	else: l[v] = u
	r -= 1
if 1 not in c: r -= 1
print("Alice" if r else "Bob")
0