結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー ああいいああいい
提出日時 2023-02-04 16:16:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 167,944 KB
最終ジャッジ日時 2023-09-16 12:56:24
合計ジャッジ時間 13,257 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,460 KB
testcase_01 AC 69 ms
71,116 KB
testcase_02 AC 69 ms
71,100 KB
testcase_03 AC 68 ms
71,496 KB
testcase_04 AC 70 ms
71,472 KB
testcase_05 AC 71 ms
71,480 KB
testcase_06 AC 70 ms
71,516 KB
testcase_07 AC 70 ms
71,332 KB
testcase_08 AC 69 ms
71,112 KB
testcase_09 AC 70 ms
71,376 KB
testcase_10 AC 69 ms
71,528 KB
testcase_11 AC 298 ms
145,992 KB
testcase_12 AC 309 ms
146,148 KB
testcase_13 AC 304 ms
147,800 KB
testcase_14 AC 316 ms
167,944 KB
testcase_15 AC 285 ms
132,632 KB
testcase_16 AC 223 ms
111,260 KB
testcase_17 AC 219 ms
111,236 KB
testcase_18 AC 70 ms
71,152 KB
testcase_19 AC 289 ms
130,184 KB
testcase_20 AC 303 ms
127,928 KB
testcase_21 AC 302 ms
127,944 KB
testcase_22 AC 287 ms
126,328 KB
testcase_23 AC 290 ms
127,744 KB
testcase_24 AC 288 ms
128,868 KB
testcase_25 AC 300 ms
127,592 KB
testcase_26 AC 316 ms
127,812 KB
testcase_27 AC 283 ms
130,276 KB
testcase_28 AC 281 ms
126,140 KB
testcase_29 AC 286 ms
129,352 KB
testcase_30 AC 331 ms
128,004 KB
testcase_31 AC 303 ms
129,744 KB
testcase_32 AC 293 ms
128,856 KB
testcase_33 AC 296 ms
128,680 KB
testcase_34 AC 279 ms
127,768 KB
testcase_35 AC 323 ms
127,940 KB
testcase_36 AC 312 ms
127,744 KB
testcase_37 AC 285 ms
127,764 KB
testcase_38 AC 319 ms
127,732 KB
testcase_39 AC 293 ms
129,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

stack = [(0,-1),(~0,-1)]
ans = 0
while stack:
    now,parent = stack.pop()
    if now < 0:
        now = ~now
        for v in G[now]:
            if v != parent:
                stack.append((v,now))
                stack.append((~v,now))
    else:
        if now == 0:
            if c[now] == 1:
                print(ans)
            else:
                print(-1)
            break
        else:
            if c[now] == 0:
                ans += 1
                c[now] = 1
                c[parent] ^= 1

0