結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー gr1msl3ygr1msl3y
提出日時 2023-06-08 22:11:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 87,356 KB
実行使用メモリ 153,496 KB
最終ジャッジ日時 2023-08-30 01:42:15
合計ジャッジ時間 11,538 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,204 KB
testcase_01 AC 69 ms
71,468 KB
testcase_02 AC 71 ms
71,160 KB
testcase_03 AC 69 ms
71,464 KB
testcase_04 AC 71 ms
71,404 KB
testcase_05 AC 71 ms
71,456 KB
testcase_06 AC 70 ms
71,372 KB
testcase_07 AC 72 ms
71,712 KB
testcase_08 AC 71 ms
71,536 KB
testcase_09 AC 70 ms
71,716 KB
testcase_10 AC 70 ms
71,404 KB
testcase_11 AC 317 ms
151,360 KB
testcase_12 AC 318 ms
151,932 KB
testcase_13 AC 313 ms
150,648 KB
testcase_14 AC 284 ms
153,496 KB
testcase_15 AC 282 ms
147,872 KB
testcase_16 AC 224 ms
123,652 KB
testcase_17 AC 219 ms
123,740 KB
testcase_18 AC 71 ms
71,324 KB
testcase_19 AC 291 ms
146,776 KB
testcase_20 AC 285 ms
147,540 KB
testcase_21 AC 281 ms
147,948 KB
testcase_22 AC 287 ms
145,236 KB
testcase_23 AC 284 ms
147,836 KB
testcase_24 AC 284 ms
145,764 KB
testcase_25 AC 290 ms
147,844 KB
testcase_26 AC 289 ms
148,044 KB
testcase_27 AC 291 ms
147,376 KB
testcase_28 AC 288 ms
143,832 KB
testcase_29 AC 286 ms
132,884 KB
testcase_30 AC 288 ms
147,900 KB
testcase_31 AC 289 ms
146,544 KB
testcase_32 AC 289 ms
145,736 KB
testcase_33 AC 289 ms
145,544 KB
testcase_34 AC 288 ms
147,876 KB
testcase_35 AC 295 ms
148,140 KB
testcase_36 AC 295 ms
147,780 KB
testcase_37 AC 287 ms
147,676 KB
testcase_38 AC 293 ms
147,644 KB
testcase_39 AC 288 ms
149,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

C = [0]+list(map(int, input().split()))
parent = [-1]*(N+1)
task = [1]
for v in task:
    for u in graph[v]:
        if parent[v] == u:
            continue
        task.append(u)
        parent[u] = v

ans = 0
for v in task[1:][::-1]:
    if C[v]:
        continue
    C[parent[v]] ^= 1
    C[v] = 1
    ans += 1

print(ans if C[1] else -1)
0