結果

問題 No.2726 Rooted Tree Nim
ユーザー ゼットゼット
提出日時 2024-04-12 22:56:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 134,540 KB
最終ジャッジ日時 2024-04-12 22:56:39
合計ジャッジ時間 7,796 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,148 KB
testcase_01 AC 553 ms
78,296 KB
testcase_02 AC 358 ms
105,960 KB
testcase_03 AC 492 ms
133,536 KB
testcase_04 AC 556 ms
133,368 KB
testcase_05 AC 350 ms
134,080 KB
testcase_06 AC 351 ms
134,160 KB
testcase_07 AC 504 ms
133,892 KB
testcase_08 AC 473 ms
134,540 KB
testcase_09 AC 366 ms
103,364 KB
testcase_10 AC 381 ms
103,976 KB
testcase_11 AC 464 ms
103,288 KB
testcase_12 AC 439 ms
130,748 KB
testcase_13 AC 381 ms
103,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q=int(input())
for _ in range(Q):
  N,K=map(int,input().split())
  G=[[] for i in range(N)]
  for i in range(N-1):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
  dist=[-1]*N
  dist[0]=0
  from collections import deque
  S=deque()
  S.append(0)
  while S:
    x=S.pop()
    for y in G[x]:
      if dist[y]>=0:
        continue
      dist[y]=dist[x]+1
      S.append(y)
  ans=0
  A=list(map(int,input().split()))
  for i in range(1,N):
    if dist[i]%2==1:
      ans^=A[i]%(K+1)
  if ans!=0:
    print('K')
  else:
    print('P')
0