結果
問題 | No.2205 Lights Out on Christmas Tree |
ユーザー |
|
提出日時 | 2023-02-03 22:28:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 576 ms / 2,000 ms |
コード長 | 657 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 269,188 KB |
最終ジャッジ日時 | 2024-07-02 20:32:30 |
合計ジャッジ時間 | 9,995 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
import syssys.setrecursionlimit(5*10**5)input = sys.stdin.readlinefrom collections import defaultdict, deque, Counterfrom heapq import heappop, heappushfrom bisect import bisect_left, bisect_rightfrom math import gcdn = 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 = 0def dfs(crr,pre):global cntfor nxt in graph[crr]:if nxt == pre: continuedfs(nxt,crr)if crr != 0 and c[crr] == 0:cnt += 1c[crr] ^= 1c[pre] ^= 1dfs(0, -1)if sum(c) == n:print(cnt)else:print(-1)