結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 双六双六
提出日時 2020-08-30 03:17:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,274 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 82,300 KB
最終ジャッジ日時 2023-08-09 10:43:18
合計ジャッジ時間 5,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,376 KB
testcase_01 AC 85 ms
71,792 KB
testcase_02 AC 86 ms
71,452 KB
testcase_03 AC 86 ms
71,592 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 88 ms
71,624 KB
testcase_07 AC 88 ms
71,628 KB
testcase_08 AC 87 ms
71,356 KB
testcase_09 AC 87 ms
71,552 KB
testcase_10 AC 88 ms
71,756 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 164 ms
79,092 KB
testcase_14 AC 165 ms
78,988 KB
testcase_15 AC 172 ms
78,904 KB
testcase_16 AC 164 ms
78,584 KB
testcase_17 WA -
testcase_18 AC 190 ms
79,380 KB
testcase_19 AC 228 ms
80,764 KB
testcase_20 AC 249 ms
80,812 KB
testcase_21 AC 297 ms
81,700 KB
testcase_22 AC 314 ms
82,300 KB
testcase_23 AC 274 ms
82,272 KB
testcase_24 WA -
testcase_25 AC 274 ms
82,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class UnionFind:
	def __init__(self, n):
		self.par = [i for i in range(n + 1)]
		self.rank = [0] * (n + 1)
		self.size = [1] * (n + 1)

	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]

	def same_check(self, x, y):
		return self.find(x) == self.find(y)

	def union(self, x, y):
		x = self.find(x); y = self.find(y)
		if self.rank[x] < self.rank[y]:
			if self.same_check(x, y) != True:
				self.size[y] += self.size[x]
				self.size[x] = 0
			self.par[x] = y
		else:
			if self.same_check(x, y) != True:
				self.size[x] += self.size[y]
				self.size[y] = 0
			self.par[y] = x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1

	def siz(self, x):
		x = self.find(x)
		return self.size[x]

#処理内容
def main():
	N = int(input())
	UF = UnionFind(N)
	for i in range(N - 1):
		a, b = getlist()
		UF.union(a, b)

	for i in range(N):
		UF.par[i] = UF.find(i)

	for i in range(N):
		if UF.size[i] >= N - 1:
			print("Bob")
			return

	print("Alice")

if __name__ == '__main__':
	main()
0