結果
| 問題 |
No.1153 ねこちゃんゲーム
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:25:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,694 bytes |
| コンパイル時間 | 266 ms |
| コンパイル使用メモリ | 81,900 KB |
| 実行使用メモリ | 132,956 KB |
| 最終ジャッジ日時 | 2025-06-12 19:26:32 |
| 合計ジャッジ時間 | 26,424 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 29 TLE * 1 -- * 4 |
ソースコード
def main():
import sys
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 parent and g for each node
parent = [0] * (n + 1)
g = [0] * (n + 1)
visited = [False] * (n + 1)
stack = [(1, -1, False)]
while stack:
u, p, visited_flag = stack.pop()
if visited_flag:
mex_set = set()
for v in edges[u]:
if v == p:
continue
mex_set.add(g[v])
mex = 0
while mex in mex_set:
mex += 1
g[u] = mex
else:
parent[u] = p
visited[u] = True
stack.append((u, p, True))
for v in edges[u]:
if v != p and not visited[v]:
stack.append((v, u, False))
# Calculate total XOR
total = 0
for ai in a:
total ^= g[ai]
if total == 0:
print("-1 -1")
return
# Find the first possible move
for idx in range(m):
u = a[idx]
target = g[u] ^ total
# Check each neighbor, excluding parent
found = False
for v in edges[u]:
if v == parent[u]:
continue
if g[v] == target:
print(idx + 1, v)
return
# If no move found, which shouldn't happen as per game theory
print("-1 -1")
if __name__ == "__main__":
main()
gew1fw