結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 双六双六
提出日時 2020-08-30 03:13:45
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,270 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 82,380 KB
最終ジャッジ日時 2023-08-09 10:42:52
合計ジャッジ時間 6,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,488 KB
testcase_01 AC 88 ms
71,528 KB
testcase_02 AC 91 ms
71,528 KB
testcase_03 AC 88 ms
71,692 KB
testcase_04 AC 86 ms
71,632 KB
testcase_05 AC 89 ms
71,436 KB
testcase_06 AC 88 ms
71,580 KB
testcase_07 AC 91 ms
71,784 KB
testcase_08 AC 88 ms
71,792 KB
testcase_09 AC 89 ms
71,304 KB
testcase_10 WA -
testcase_11 AC 91 ms
71,488 KB
testcase_12 AC 90 ms
71,732 KB
testcase_13 AC 173 ms
79,140 KB
testcase_14 AC 168 ms
78,988 KB
testcase_15 AC 167 ms
78,824 KB
testcase_16 AC 160 ms
78,632 KB
testcase_17 AC 175 ms
78,888 KB
testcase_18 AC 193 ms
79,424 KB
testcase_19 WA -
testcase_20 AC 255 ms
80,760 KB
testcase_21 AC 293 ms
81,696 KB
testcase_22 AC 326 ms
82,380 KB
testcase_23 AC 272 ms
82,260 KB
testcase_24 AC 256 ms
81,328 KB
testcase_25 AC 277 ms
81,988 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:
			print("Bob")
			return

	print("Alice")

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