結果
問題 | No.2205 Lights Out on Christmas Tree |
ユーザー | McGregorsh |
提出日時 | 2023-03-18 22:18:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 629 ms / 2,000 ms |
コード長 | 1,870 bytes |
コンパイル時間 | 368 ms |
コンパイル使用メモリ | 81,880 KB |
実行使用メモリ | 289,836 KB |
最終ジャッジ日時 | 2024-09-18 13:35:48 |
合計ジャッジ時間 | 14,561 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
89,480 KB |
testcase_01 | AC | 124 ms
89,240 KB |
testcase_02 | AC | 122 ms
89,096 KB |
testcase_03 | AC | 124 ms
89,444 KB |
testcase_04 | AC | 125 ms
89,100 KB |
testcase_05 | AC | 129 ms
89,612 KB |
testcase_06 | AC | 125 ms
89,212 KB |
testcase_07 | AC | 123 ms
89,696 KB |
testcase_08 | AC | 125 ms
89,592 KB |
testcase_09 | AC | 129 ms
89,388 KB |
testcase_10 | AC | 143 ms
89,628 KB |
testcase_11 | AC | 353 ms
147,476 KB |
testcase_12 | AC | 324 ms
147,612 KB |
testcase_13 | AC | 296 ms
145,748 KB |
testcase_14 | AC | 351 ms
154,436 KB |
testcase_15 | AC | 629 ms
289,836 KB |
testcase_16 | AC | 307 ms
122,964 KB |
testcase_17 | AC | 277 ms
122,068 KB |
testcase_18 | AC | 127 ms
89,480 KB |
testcase_19 | AC | 350 ms
144,868 KB |
testcase_20 | AC | 282 ms
139,400 KB |
testcase_21 | AC | 355 ms
141,392 KB |
testcase_22 | AC | 332 ms
144,068 KB |
testcase_23 | AC | 352 ms
142,732 KB |
testcase_24 | AC | 335 ms
142,492 KB |
testcase_25 | AC | 354 ms
142,536 KB |
testcase_26 | AC | 372 ms
143,080 KB |
testcase_27 | AC | 346 ms
145,248 KB |
testcase_28 | AC | 330 ms
143,444 KB |
testcase_29 | AC | 334 ms
144,284 KB |
testcase_30 | AC | 360 ms
141,728 KB |
testcase_31 | AC | 366 ms
144,664 KB |
testcase_32 | AC | 354 ms
142,280 KB |
testcase_33 | AC | 342 ms
142,368 KB |
testcase_34 | AC | 320 ms
141,456 KB |
testcase_35 | AC | 371 ms
142,240 KB |
testcase_36 | AC | 371 ms
142,112 KB |
testcase_37 | AC | 342 ms
142,552 KB |
testcase_38 | AC | 289 ms
139,868 KB |
testcase_39 | AC | 288 ms
141,120 KB |
ソースコード
import sys, re from fractions import Fraction from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement, permutations from bisect import bisect, bisect_left, bisect_right from functools import reduce from decimal import Decimal, getcontext, ROUND_HALF_UP def i_input(): return int(input()) def i_map(): return map(int, input().split()) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_str(N): return [s_list() for _ in range(N)] def s_row_list(N): return [list(s_input()) for _ in range(N)] def lcm(a, b): return a * b // gcd(a, b) def get_distance(x1, y1, x2, y2): d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) return d def rotate(table): n_fild = [] for x in zip(*table[::-1]): n_fild.append(x) return n_fild sys.setrecursionlimit(10 ** 7) INF = float('inf') MOD = 10 ** 9 + 7 MOD2 = 998244353 def main(): def dfs(s, p): for i in nums[s]: if i == p: continue dfs(i, s) if A[i] == 0: ans.append(1) A[i] = 1 A[s] = not A[s] N = int(input()) nums = [[] for i in range(N)] for i in range(N-1): a, b = i_map() a -= 1 b -= 1 nums[a].append(b) nums[b].append(a) A = i_list() cost = A.count(0) if cost % 2 == 1: print(-1) exit() ans = [] dfs(0, -1) print(sum(ans)) if __name__ == '__main__': main()