結果

問題 No.2205 Lights Out on Christmas Tree
ユーザー flygonflygon
提出日時 2023-02-03 22:28:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 572 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 293,004 KB
最終ジャッジ日時 2023-09-15 18:32:45
合計ジャッジ時間 11,322 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,680 KB
testcase_01 AC 91 ms
71,576 KB
testcase_02 AC 93 ms
71,680 KB
testcase_03 AC 92 ms
71,548 KB
testcase_04 AC 92 ms
71,636 KB
testcase_05 AC 91 ms
71,740 KB
testcase_06 AC 95 ms
71,540 KB
testcase_07 AC 92 ms
71,376 KB
testcase_08 AC 95 ms
71,680 KB
testcase_09 AC 93 ms
71,440 KB
testcase_10 AC 96 ms
71,576 KB
testcase_11 AC 267 ms
138,464 KB
testcase_12 AC 261 ms
138,452 KB
testcase_13 AC 262 ms
137,524 KB
testcase_14 AC 243 ms
127,188 KB
testcase_15 AC 572 ms
293,004 KB
testcase_16 AC 204 ms
111,064 KB
testcase_17 AC 201 ms
111,096 KB
testcase_18 AC 93 ms
71,620 KB
testcase_19 AC 256 ms
133,560 KB
testcase_20 AC 255 ms
125,456 KB
testcase_21 AC 257 ms
125,480 KB
testcase_22 AC 243 ms
128,956 KB
testcase_23 AC 253 ms
125,752 KB
testcase_24 AC 251 ms
128,784 KB
testcase_25 AC 257 ms
125,632 KB
testcase_26 AC 273 ms
125,768 KB
testcase_27 AC 256 ms
134,704 KB
testcase_28 AC 243 ms
129,056 KB
testcase_29 AC 244 ms
129,396 KB
testcase_30 AC 271 ms
125,508 KB
testcase_31 AC 254 ms
133,672 KB
testcase_32 AC 258 ms
129,208 KB
testcase_33 AC 254 ms
129,068 KB
testcase_34 AC 244 ms
125,360 KB
testcase_35 AC 273 ms
126,832 KB
testcase_36 AC 271 ms
126,804 KB
testcase_37 AC 248 ms
125,848 KB
testcase_38 AC 271 ms
125,520 KB
testcase_39 AC 250 ms
133,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n = int(input())
graph = [[] for i in range(n+1)]
for i in range(n-1):
  a,b = map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

c = list(map(int,input().split()))
cnt = 0
def dfs(crr,pre):
  global cnt
  for nxt in graph[crr]:
    if nxt == pre: continue
    dfs(nxt,crr)
  if crr != 0 and c[crr] == 0:
    cnt += 1
    c[crr] ^= 1
    c[pre] ^= 1

dfs(0, -1)
if sum(c) == n:
  print(cnt)
else:
  print(-1)
0