結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー 👑 p-adic
提出日時 2023-05-31 17:11:54
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 366 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 101,744 KB
最終ジャッジ日時 2024-12-28 13:56:31
合計ジャッジ時間 40,896 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 30
権限があれば一括ダウンロードができます

ソースコード

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())
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()
			C[j]+=C[i]
			E[j].remove(i)
			M.add(j)
	L=M
print([-C[j],-1][C[j]%2])
0