結果
問題 | No.2205 Lights Out on Christmas Tree |
ユーザー |
|
提出日時 | 2023-02-06 15:09:18 |
言語 | Python3 (3.11.2 + numpy 1.24.2 + scipy 1.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,172 bytes |
コンパイル時間 | 75 ms |
コンパイル使用メモリ | 10,900 KB |
実行使用メモリ | 73,612 KB |
最終ジャッジ日時 | 2023-09-18 02:30:17 |
合計ジャッジ時間 | 24,329 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
7,856 KB |
testcase_01 | AC | 16 ms
7,940 KB |
testcase_02 | AC | 16 ms
7,932 KB |
testcase_03 | AC | 16 ms
7,856 KB |
testcase_04 | WA | - |
testcase_05 | AC | 16 ms
7,808 KB |
testcase_06 | AC | 16 ms
7,888 KB |
testcase_07 | AC | 16 ms
7,884 KB |
testcase_08 | AC | 16 ms
7,888 KB |
testcase_09 | AC | 16 ms
7,952 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 642 ms
46,112 KB |
testcase_14 | WA | - |
testcase_15 | AC | 822 ms
71,844 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 16 ms
7,800 KB |
testcase_19 | WA | - |
testcase_20 | AC | 641 ms
44,324 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 649 ms
44,752 KB |
testcase_39 | AC | 642 ms
45,496 KB |
ソースコード
def main(): N = int(input()) graphs = [[] for _ in range(N)] for _ in range(N-1): dep, dest = map(lambda n: int(n)-1, input().split()) graphs[dep].append(dest) graphs[dest].append(dep) color = list(map(int, input().split())) if color.count(0) % 2: print(-1) return moved = set() searched = set() stack = [] stack.append([0, None]) moved.add(0) change_ctr = 0 while stack: ctr_child = 0 for node_idx in graphs[stack[-1][0]]: if node_idx not in moved: stack.append((node_idx, stack[-1][0])) moved.add(node_idx) ctr_child += 1 if ctr_child == 0: current_node_idx, parent_idx = stack.pop() if color[current_node_idx] == 0: if parent_idx is not None: color[current_node_idx] = 1 color[parent_idx] ^= 1 change_ctr += 1 else: print(-1) return searched.add(current_node_idx) print(change_ctr) if __name__ == "__main__": main()