結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー 👑 p-adicp-adic
提出日時 2023-05-31 17:50:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 445 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 102,444 KB
最終ジャッジ日時 2023-08-28 01:35:49
合計ジャッジ時間 36,589 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 16 ms
7,828 KB
testcase_02 AC 16 ms
7,840 KB
testcase_03 AC 16 ms
7,840 KB
testcase_04 AC 16 ms
7,828 KB
testcase_05 AC 16 ms
7,784 KB
testcase_06 AC 16 ms
7,868 KB
testcase_07 AC 16 ms
7,832 KB
testcase_08 AC 16 ms
7,808 KB
testcase_09 AC 16 ms
7,820 KB
testcase_10 WA -
testcase_11 AC 1,200 ms
101,132 KB
testcase_12 AC 1,211 ms
101,176 KB
testcase_13 AC 1,179 ms
100,976 KB
testcase_14 AC 1,165 ms
94,600 KB
testcase_15 WA -
testcase_16 AC 782 ms
56,572 KB
testcase_17 AC 790 ms
56,632 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1,263 ms
78,208 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 1,256 ms
93,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

I,R=input,range
def S(n):
	return abs(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
S=[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()
			S[j]+=C[i]
			A[j]+=A[i]
			E[j].remove(i)
			M.add(j)
	for j in M:
		A[j]+=S[j]
		C[j]=(C[j]+S[j])%2
	L=M
print([A[j],-1][C[j]])
0