結果

問題 No.2726 Rooted Tree Nim
ユーザー ゼット
提出日時 2024-04-12 22:56:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 81,964 KB
実行使用メモリ 134,512 KB
最終ジャッジ日時 2024-10-02 23:40:59
合計ジャッジ時間 5,722 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

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