結果
| 問題 | No.2205 Lights Out on Christmas Tree |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-12 13:41:39 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 385 ms / 2,000 ms |
| コード長 | 458 bytes |
| 記録 | |
| コンパイル時間 | 214 ms |
| コンパイル使用メモリ | 95,992 KB |
| 実行使用メモリ | 277,464 KB |
| 最終ジャッジ日時 | 2026-07-08 20:23:10 |
| 合計ジャッジ時間 | 11,268 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
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)