結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー 👑 seekworserseekworser
提出日時 2023-01-31 19:23:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 1,099 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 163,964 KB
最終ジャッジ日時 2023-09-13 11:52:44
合計ジャッジ時間 12,564 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,348 KB
testcase_01 AC 70 ms
71,252 KB
testcase_02 AC 70 ms
71,540 KB
testcase_03 AC 71 ms
71,088 KB
testcase_04 AC 70 ms
71,248 KB
testcase_05 AC 70 ms
71,488 KB
testcase_06 AC 72 ms
71,400 KB
testcase_07 AC 70 ms
71,268 KB
testcase_08 AC 69 ms
71,256 KB
testcase_09 AC 70 ms
71,412 KB
testcase_10 AC 71 ms
71,140 KB
testcase_11 AC 324 ms
161,452 KB
testcase_12 AC 323 ms
161,912 KB
testcase_13 AC 324 ms
160,768 KB
testcase_14 AC 300 ms
163,964 KB
testcase_15 AC 280 ms
135,488 KB
testcase_16 AC 228 ms
121,308 KB
testcase_17 AC 224 ms
121,420 KB
testcase_18 AC 70 ms
71,336 KB
testcase_19 AC 290 ms
132,364 KB
testcase_20 AC 303 ms
134,552 KB
testcase_21 AC 301 ms
137,384 KB
testcase_22 AC 290 ms
137,716 KB
testcase_23 AC 294 ms
138,268 KB
testcase_24 AC 297 ms
133,848 KB
testcase_25 AC 307 ms
136,244 KB
testcase_26 AC 327 ms
135,352 KB
testcase_27 AC 294 ms
134,368 KB
testcase_28 AC 289 ms
141,012 KB
testcase_29 AC 289 ms
131,164 KB
testcase_30 AC 321 ms
135,092 KB
testcase_31 AC 285 ms
133,320 KB
testcase_32 AC 307 ms
133,300 KB
testcase_33 AC 300 ms
135,084 KB
testcase_34 AC 281 ms
138,508 KB
testcase_35 AC 321 ms
135,696 KB
testcase_36 AC 320 ms
134,656 KB
testcase_37 AC 287 ms
138,488 KB
testcase_38 AC 327 ms
135,380 KB
testcase_39 AC 290 ms
134,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
adj = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)
c = list(map(int, input().split()))
# for i in range(n): print(adj[i])

q = [(0, 0)]
pars = [-1] * n
route=[]
while q:
    v, par = q.pop()
    if pars[v] != -1: continue
    pars[v] = par
    route.append(v)
    for nv in adj[v]:
        if nv == par: continue
        q.append((nv, v))
# print(route)
# print(pars)

ans = 0

for v in reversed(route):
    if v == 0: continue
    par = pars[v]
    if not c[v] % 2:
        c[par] += 1
        ans += 1

# print(c)
if not c[0] % 2: print(-1)
else: print(ans)
0