結果

問題 No.2726 Rooted Tree Nim
ユーザー PNJPNJ
提出日時 2024-04-12 22:30:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 722 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 157,228 KB
最終ジャッジ日時 2024-04-12 22:31:04
合計ジャッジ時間 9,621 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,076 KB
testcase_01 AC 648 ms
77,276 KB
testcase_02 WA -
testcase_03 AC 1,017 ms
133,152 KB
testcase_04 WA -
testcase_05 AC 413 ms
157,228 KB
testcase_06 AC 387 ms
156,976 KB
testcase_07 AC 593 ms
142,684 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
  while len(todo):
    s = todo.pop()
    for t in G[s]:
      if dist[t] == -1:
        parent[t] = s
        dist[t] = dist[s] + 1
        todo.append(t)
  H = [(dist[s],s) for s in range(N)]
  H.sort()
  while len(H):
    d,s = H.pop()
    if d % 2:
      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