結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー 👑 p-adic
提出日時 2023-05-31 17:25:35
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 414 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 103,328 KB
最終ジャッジ日時 2024-12-28 13:57:34
合計ジャッジ時間 39,065 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 11 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

I,R=input,range
def S(n):
	return int(n)-1
def J():
	return map(S,I().split())
N=int(I())
E=[set()for i in R(N)]
for i in R(N-1):
	a,b=J()
	E[a].add(b),E[b].add(a)
C=list(J())
A=[0]*N
L=set()
for i in R(N):
	if len(E[i])<2:L.add(i)
while len(L):
	M=set()
	for i in L:
		if len(E[i]):
			j=E[i].pop()
			A[j]+=C[i]+A[i]
			E[j].remove(i)
			M.add(j)
	for j in M:
		C[j]=-((C[j]+A[j])%2)
	L=M
print([-A[j],-1][C[j]])
0