結果

問題 No.2800 Game on Tree Inverse
ユーザー shobonvipshobonvip
提出日時 2024-06-27 01:18:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,669 ms / 4,000 ms
コード長 2,834 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 303,348 KB
最終ジャッジ日時 2024-06-27 01:22:59
合計ジャッジ時間 82,434 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,120 KB
testcase_01 AC 46 ms
53,248 KB
testcase_02 AC 45 ms
52,992 KB
testcase_03 AC 2,660 ms
247,388 KB
testcase_04 AC 1,564 ms
222,832 KB
testcase_05 AC 1,517 ms
242,748 KB
testcase_06 AC 1,526 ms
256,304 KB
testcase_07 AC 1,832 ms
277,508 KB
testcase_08 AC 1,845 ms
287,092 KB
testcase_09 AC 1,716 ms
303,348 KB
testcase_10 AC 1,708 ms
227,432 KB
testcase_11 AC 2,553 ms
267,836 KB
testcase_12 AC 2,248 ms
267,292 KB
testcase_13 AC 1,681 ms
236,348 KB
testcase_14 AC 1,743 ms
244,872 KB
testcase_15 AC 2,488 ms
271,416 KB
testcase_16 AC 1,730 ms
245,384 KB
testcase_17 AC 2,383 ms
267,772 KB
testcase_18 AC 1,658 ms
225,120 KB
testcase_19 AC 1,712 ms
248,156 KB
testcase_20 AC 2,541 ms
266,108 KB
testcase_21 AC 1,773 ms
235,628 KB
testcase_22 AC 1,676 ms
258,452 KB
testcase_23 AC 2,230 ms
268,160 KB
testcase_24 AC 1,854 ms
229,092 KB
testcase_25 AC 1,540 ms
225,128 KB
testcase_26 AC 1,511 ms
234,684 KB
testcase_27 AC 2,241 ms
265,148 KB
testcase_28 AC 1,683 ms
265,504 KB
testcase_29 AC 2,439 ms
255,512 KB
testcase_30 AC 1,655 ms
223,168 KB
testcase_31 AC 1,911 ms
264,656 KB
testcase_32 AC 2,669 ms
269,372 KB
testcase_33 AC 2,132 ms
269,308 KB
testcase_34 AC 2,182 ms
278,080 KB
testcase_35 AC 2,427 ms
270,092 KB
testcase_36 AC 59 ms
64,108 KB
testcase_37 AC 67 ms
65,024 KB
testcase_38 AC 63 ms
62,592 KB
testcase_39 AC 53 ms
60,144 KB
testcase_40 AC 46 ms
53,120 KB
testcase_41 AC 42 ms
52,992 KB
testcase_42 AC 60 ms
63,872 KB
testcase_43 AC 67 ms
65,792 KB
testcase_44 AC 62 ms
64,128 KB
testcase_45 AC 58 ms
62,208 KB
testcase_46 AC 78 ms
69,248 KB
testcase_47 AC 206 ms
79,472 KB
testcase_48 AC 195 ms
79,276 KB
testcase_49 AC 284 ms
84,068 KB
testcase_50 AC 239 ms
80,624 KB
testcase_51 AC 1,013 ms
159,276 KB
testcase_52 AC 287 ms
85,532 KB
testcase_53 AC 386 ms
96,388 KB
testcase_54 AC 1,005 ms
158,144 KB
testcase_55 AC 1,538 ms
206,120 KB
testcase_56 AC 1,258 ms
179,840 KB
testcase_57 AC 1,691 ms
219,540 KB
testcase_58 AC 729 ms
129,868 KB
testcase_59 AC 1,048 ms
146,232 KB
testcase_60 AC 815 ms
127,264 KB
testcase_61 AC 526 ms
112,412 KB
testcase_62 AC 734 ms
127,088 KB
testcase_63 AC 737 ms
133,244 KB
testcase_64 AC 442 ms
100,164 KB
testcase_65 AC 431 ms
99,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class binary_trie:
	def __init__(self, MAX_LOG):
		self.ch = [-1] * 2
		self.cnt = [0]
		self.id = 1
		self.xor_all = 0
		self.max_log = MAX_LOG

	def insert(self, val):
		val ^= self.xor_all
		node = 0
		for b in range(self.max_log-1, -1, -1):
			f = val >> b & 1
			self.cnt[node] += 1
			if self.ch[(node<<1)|f] == -1:
				self.ch[(node<<1)|f] = self.id
				self.ch.append(-1)
				self.ch.append(-1)
				self.cnt.append(0)
				node = self.id
				self.id += 1
			else:
				node = self.ch[(node<<1)|f]
		self.cnt[node] += 1
	
	def size(self, node):
		if node == -1: return 0
		return self.cnt[node]
	
	def count(self, val):
		val ^= self.xor_all
		node = 0
		for b in range(self.max_log-1, -1, -1):
			if node == -1: break
			node = self.ch[(node<<1)|(val>>b&1)]
		return self.size(node)

	def xth(self, x):
		node = 0
		ret = 0
		for b in range(self.max_log-1, -1, -1):
			f = self.xor_all>>b&1
			if self.size(self.ch[(node<<1)|f]) <= x:
				x -= self.size(self.ch[(node<<1)|f])
				node = self.ch[(node<<1)|(f^1)]
				ret = (ret<<1)|(f^1)
			else:
				node = self.ch[(node<<1)|f]
				ret = (ret<<1)|f
		return ret ^ self.xor_all
	
	def mex(self):
		ub = self.cnt[0]
		lb = -1
		while ub - lb > 1:
			t = (ub + lb) // 2
			if self.xth(t) == t: lb = t
			else: ub = t
		return lb + 1

	def xor_to_all(self, x):
		self.xor_all ^= x
		return

n = int(input())
ikeru = [[] for i in range(n)]
for i in range(n-1):
	u, v = map(int,input().split())
	u -= 1
	v -= 1
	ikeru[u].append(v)
	ikeru[v].append(u)

dp = [0] * n
ep = [binary_trie(18) for i in range(n)]
re = [i for i in range(n)]

mada = [~0, 0]
tansaku = [0] * n
tansaku[0] = 1
while mada:
	i = mada.pop()
	if i >= 0:
		for j in ikeru[i]:
			if tansaku[j] == 1: continue
			tansaku[j] = 1
			mada.append(~j)
			mada.append(j)
	else:
		i = ~i
		x = 0
		mxval = 0
		mxind = i
		for j in ikeru[i]:
			if tansaku[j] == 2:
				x ^= dp[j]
				if mxval < ep[re[j]].cnt[0]:
					mxval = ep[re[j]].cnt[0]
					mxind = j
		
		ep[re[mxind]].xor_to_all(dp[mxind]^x)

		for j in ikeru[i]:
			if tansaku[j] == 2:
				if j == mxind:
					continue
				mxz = ep[re[j]].cnt[0]
				for z in range(mxz):
					tar = ep[re[j]].xth(z)
					if ep[re[mxind]].count(tar^x^dp[j]) == 0:
						ep[re[mxind]].insert(tar^x^dp[j])
		
		if ep[re[mxind]].count(x) == 0:
			ep[re[mxind]].insert(x)
		
		re[i] = re[mxind]
		dp[i] = ep[re[i]].mex()
		tansaku[i] = 2
	
ans = []

mada = [0]
tansaku = [0] * n
tansaku[0] = 1
gogo = [0] * n
while mada:
	i = mada.pop()
	if i >= 0:
		x = gogo[i]
		for j in ikeru[i]:
			if tansaku[j] == 1: continue
			x ^= dp[j]
		
		if x == 0:
			ans.append(i)
		
		for j in ikeru[i]:
			if tansaku[j] == 1: continue
			tansaku[j] = 1
			gogo[j] = x^dp[j]
			mada.append(j)		

if len(ans) == 0:
	print("Bob")
else:
	print("Alice")
	print(len(ans))
	ans.sort()
	print(*[x+1 for x in ans])
0