結果

問題 No.2726 Rooted Tree Nim
ユーザー PNJPNJ
提出日時 2024-04-12 22:34:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 774 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 154,236 KB
最終ジャッジ日時 2024-04-12 22:34:43
合計ジャッジ時間 7,640 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,236 KB
testcase_01 AC 620 ms
78,260 KB
testcase_02 WA -
testcase_03 AC 520 ms
141,468 KB
testcase_04 WA -
testcase_05 AC 364 ms
154,024 KB
testcase_06 AC 376 ms
153,900 KB
testcase_07 AC 493 ms
154,236 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)
  for s in range(N):
    if dist[s] % 2 == 0:
      A[s] = 0
  while len(visit):
    s = visit.pop()
    if s != 0:
      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