結果

問題 No.2726 Rooted Tree Nim
ユーザー PNJPNJ
提出日時 2024-04-12 22:24:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 153,896 KB
最終ジャッジ日時 2024-04-12 22:25:02
合計ジャッジ時間 8,136 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,884 KB
testcase_01 AC 595 ms
77,816 KB
testcase_02 WA -
testcase_03 AC 520 ms
141,344 KB
testcase_04 WA -
testcase_05 AC 390 ms
153,896 KB
testcase_06 AC 395 ms
153,648 KB
testcase_07 AC 520 ms
153,368 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
for _ in range(T):
  N,K = map(int,input().split())
  G = [[] for i in range(N)]
  for i in range(N-1):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)
  A = list(map(int,input().split()))
  parent = [-1 for i in range(N)]
  todo = [0]
  dist = [-1 for i in range(N)]
  dist[0] = 0
  visit = []
  while len(todo):
    s = todo.pop()
    visit.append(s)
    for t in G[s]:
      if dist[t] == -1:
        parent[t] = s
        dist[t] = dist[s] + 1
        todo.append(t)
  while len(visit):
    s = visit.pop()
    if s == 0:
      break
    if dist[s] % 2 == 0:
      continue
    A[parent[s]] += A[s]
  g = 0
  for s in G[0]:
    g ^= A[s] % (K + 1)
  if g:
    print('K')
  else:
    print('P')
0