結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー ニックネームニックネーム
提出日時 2023-02-03 22:29:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,008 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 68,312 KB
最終ジャッジ日時 2023-09-15 18:34:04
合計ジャッジ時間 28,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,664 KB
testcase_01 AC 18 ms
8,500 KB
testcase_02 AC 18 ms
8,624 KB
testcase_03 AC 18 ms
8,620 KB
testcase_04 AC 18 ms
8,560 KB
testcase_05 AC 18 ms
8,468 KB
testcase_06 AC 18 ms
8,636 KB
testcase_07 AC 18 ms
8,584 KB
testcase_08 AC 18 ms
8,620 KB
testcase_09 AC 18 ms
8,512 KB
testcase_10 AC 18 ms
8,548 KB
testcase_11 AC 994 ms
66,924 KB
testcase_12 AC 984 ms
66,844 KB
testcase_13 AC 685 ms
46,452 KB
testcase_14 AC 909 ms
60,308 KB
testcase_15 AC 993 ms
67,992 KB
testcase_16 AC 624 ms
45,996 KB
testcase_17 AC 612 ms
46,012 KB
testcase_18 AC 18 ms
8,664 KB
testcase_19 AC 993 ms
67,344 KB
testcase_20 AC 684 ms
44,932 KB
testcase_21 AC 1,008 ms
67,048 KB
testcase_22 AC 982 ms
66,916 KB
testcase_23 AC 972 ms
66,056 KB
testcase_24 AC 962 ms
67,004 KB
testcase_25 AC 981 ms
67,596 KB
testcase_26 AC 965 ms
68,312 KB
testcase_27 AC 978 ms
66,776 KB
testcase_28 AC 993 ms
66,844 KB
testcase_29 AC 986 ms
66,328 KB
testcase_30 AC 973 ms
68,120 KB
testcase_31 AC 984 ms
67,080 KB
testcase_32 AC 976 ms
67,912 KB
testcase_33 AC 959 ms
67,804 KB
testcase_34 AC 965 ms
65,660 KB
testcase_35 AC 973 ms
67,576 KB
testcase_36 AC 981 ms
67,528 KB
testcase_37 AC 972 ms
65,684 KB
testcase_38 AC 689 ms
45,160 KB
testcase_39 AC 690 ms
45,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n = int(input())
adj = [[] for _ in range(n)]
for _ 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()))
if c.count(0)%2: print(-1); exit()
dq = deque([0]); topo = []; par = [-1]*n; chi = [[] for _ in range(n)]
while dq:
    p = dq.popleft(); topo.append(p)
    for v in adj[p]:
        if v!=par[p]: dq.append(v); par[v] = p; chi[p].append(v)
ans = 0
for v in topo[::-1]:
    if not c[v]: c[v] ^= 1; c[par[v]] ^= 1; ans += 1
print(ans)
0