結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-02-03 23:31:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 174,896 KB
最終ジャッジ日時 2023-09-15 19:47:58
合計ジャッジ時間 12,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,136 KB
testcase_01 AC 68 ms
71,260 KB
testcase_02 AC 70 ms
71,364 KB
testcase_03 AC 70 ms
71,360 KB
testcase_04 AC 70 ms
71,444 KB
testcase_05 AC 69 ms
71,420 KB
testcase_06 AC 71 ms
71,440 KB
testcase_07 AC 70 ms
71,412 KB
testcase_08 AC 71 ms
71,140 KB
testcase_09 AC 70 ms
71,328 KB
testcase_10 AC 69 ms
71,308 KB
testcase_11 AC 371 ms
174,896 KB
testcase_12 AC 393 ms
173,448 KB
testcase_13 AC 365 ms
169,820 KB
testcase_14 AC 329 ms
171,204 KB
testcase_15 AC 310 ms
134,320 KB
testcase_16 AC 254 ms
123,208 KB
testcase_17 AC 254 ms
123,200 KB
testcase_18 AC 71 ms
71,016 KB
testcase_19 AC 326 ms
134,260 KB
testcase_20 AC 334 ms
133,220 KB
testcase_21 AC 332 ms
136,956 KB
testcase_22 AC 326 ms
147,616 KB
testcase_23 AC 321 ms
139,788 KB
testcase_24 AC 330 ms
133,004 KB
testcase_25 AC 332 ms
135,512 KB
testcase_26 AC 341 ms
134,348 KB
testcase_27 AC 315 ms
134,064 KB
testcase_28 AC 323 ms
152,276 KB
testcase_29 AC 324 ms
142,612 KB
testcase_30 AC 342 ms
134,548 KB
testcase_31 AC 320 ms
133,280 KB
testcase_32 AC 337 ms
132,832 KB
testcase_33 AC 332 ms
132,780 KB
testcase_34 AC 318 ms
141,112 KB
testcase_35 AC 347 ms
133,488 KB
testcase_36 AC 346 ms
133,376 KB
testcase_37 AC 320 ms
140,584 KB
testcase_38 AC 347 ms
134,664 KB
testcase_39 AC 320 ms
134,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
e = [[] for i in range(n)]
for _ in range(n-1):
    a,b = [int(x)-1 for x in input().split()]
    e[a].append(b)
    e[b].append(a)
C = list(map(int,input().split()))
ans = 0

topo = []
vis = [0]*n
par = [-1]*n
q = [0]
vis[0] = 1
while q:
    now = q.pop()
    topo.append(now)
    for nex in e[now]:
        if vis[nex]:
            continue
        vis[nex] = 1
        par[nex] = now
        q.append(nex)

for now in topo[::-1]:
    if now == 0:
        break
    if C[now]:
        continue
    C[now] = 1
    C[par[now]] ^= 1
    ans += 1
if C[0] == 0:
    ans = -1
print(ans)
0