結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー flippergo
提出日時 2025-04-12 13:41:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 752 ms / 2,000 ms
コード長 458 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 277,216 KB
最終ジャッジ日時 2025-04-12 13:41:55
合計ジャッジ時間 14,885 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
N = int(input())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
C = [-1]+list(map(int,input().split()))
cnt = 0
def dfs(x,p):
    global cnt
    for y in G[x]:
        if y==p:continue
        dfs(y,x)
    if x!=1 and C[x]==0:
        C[x] = 1
        C[p] = 1-C[p]
        cnt += 1
dfs(1,0)
if C[1]==0:
    print(-1)
else:
    print(cnt)
0