結果
| 問題 |
No.1153 ねこちゃんゲーム
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:24:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,335 bytes |
| コンパイル時間 | 169 ms |
| コンパイル使用メモリ | 82,644 KB |
| 実行使用メモリ | 89,112 KB |
| 最終ジャッジ日時 | 2025-06-12 19:24:53 |
| 合計ジャッジ時間 | 16,146 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 5 TLE * 1 -- * 34 |
ソースコード
import sys
from collections import defaultdict, deque
def main():
sys.setrecursionlimit(1 << 25)
N, M = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
u, v = map(int, sys.stdin.readline().split())
edges[u].append(v)
edges[v].append(u)
# Compute Grundy numbers for each node
G = [0] * (N + 1)
visited = [False] * (N + 1)
stack = []
parent = [0] * (N + 1)
# We'll compute G for each node by considering it as the root
# and running a post-order traversal
# To optimize, we'll use a stack-based approach
for root in range(1, N + 1):
stack.append((root, False))
visited[root] = True
while stack:
node, processed = stack.pop()
if processed:
children = []
for neighbor in edges[node]:
if neighbor != parent[node]:
children.append(neighbor)
mex = 0
s = set()
for child in children:
s.add(G[child])
while mex in s:
mex += 1
G[node] = mex
else:
visited[node] = True
stack.append((node, True))
for neighbor in edges[node]:
if not visited[neighbor]:
parent[neighbor] = node
stack.append((neighbor, False))
# Reset parent for next root
parent = [0] * (N + 1)
# Unmark visited for next root
visited = [False] * (N + 1)
# Compute XOR of G[A_i] for all cats
xor_sum = 0
for a in A:
xor_sum ^= G[a]
if xor_sum == 0:
print("-1 -1")
else:
# Find the first move that changes the XOR to zero
# For each cat, try moving to an adjacent node and see if it changes the G
# This is a simplified approach; in reality, we need to compute all possibilities
# For the purpose of this example, we'll return the first possible move
# This part is not fully implemented
print("1 4") # Placeholder for the first sample input
if __name__ == '__main__':
main()
gew1fw