結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー ntudantuda
提出日時 2023-02-05 12:49:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 980 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 119,972 KB
最終ジャッジ日時 2023-09-17 05:33:31
合計ジャッジ時間 26,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,752 KB
testcase_01 AC 14 ms
7,808 KB
testcase_02 AC 14 ms
7,860 KB
testcase_03 AC 14 ms
7,836 KB
testcase_04 AC 13 ms
7,804 KB
testcase_05 AC 14 ms
7,952 KB
testcase_06 AC 15 ms
7,760 KB
testcase_07 AC 14 ms
7,840 KB
testcase_08 AC 15 ms
7,956 KB
testcase_09 AC 14 ms
7,808 KB
testcase_10 AC 12 ms
7,764 KB
testcase_11 AC 853 ms
84,332 KB
testcase_12 AC 838 ms
84,440 KB
testcase_13 AC 852 ms
83,740 KB
testcase_14 AC 793 ms
71,204 KB
testcase_15 AC 980 ms
119,972 KB
testcase_16 AC 516 ms
56,244 KB
testcase_17 AC 515 ms
56,452 KB
testcase_18 AC 14 ms
7,840 KB
testcase_19 AC 863 ms
83,340 KB
testcase_20 AC 848 ms
82,092 KB
testcase_21 AC 863 ms
82,208 KB
testcase_22 AC 842 ms
83,060 KB
testcase_23 AC 861 ms
82,060 KB
testcase_24 AC 844 ms
82,552 KB
testcase_25 AC 845 ms
81,748 KB
testcase_26 AC 875 ms
81,828 KB
testcase_27 AC 854 ms
83,036 KB
testcase_28 AC 851 ms
82,816 KB
testcase_29 AC 841 ms
82,724 KB
testcase_30 AC 893 ms
82,220 KB
testcase_31 AC 856 ms
83,196 KB
testcase_32 AC 861 ms
82,252 KB
testcase_33 AC 868 ms
82,276 KB
testcase_34 AC 844 ms
81,716 KB
testcase_35 AC 876 ms
81,796 KB
testcase_36 AC 930 ms
81,788 KB
testcase_37 AC 843 ms
81,816 KB
testcase_38 AC 867 ms
82,236 KB
testcase_39 AC 850 ms
83,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(200050)

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N-1)]
C = list(map(int,input().split()))
E = [[] for _ in range(N)]
for a,b in AB:
    a -= 1; b -= 1
    E[a].append(b)
    E[b].append(a)

ans = 0
def dfs(u,p):
    global ans
    cnt = 0
    for v in E[u]:
        if v != p:
            dfs(v,u)
            if C[v] == 0:
                cnt += 1
    if cnt % 2 == 1:
        C[u] ^= 1
    ans += cnt

dfs(0,-1)
if C[0] == 1:
    print(ans)
else:
    print(-1)
0