結果
問題 | No.2726 Rooted Tree Nim |
ユーザー |
![]() |
提出日時 | 2024-04-27 01:18:07 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,018 ms / 2,000 ms |
コード長 | 650 bytes |
コンパイル時間 | 244 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 69,616 KB |
最終ジャッジ日時 | 2024-11-14 17:40:53 |
合計ジャッジ時間 | 13,828 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 |
ソースコード
import sysinput = sys.stdin.readlineT=int(input())for tests in range(T):N,K=map(int,input().split())E=[[] for i in range(N)]for i in range(N-1):x,y=map(int,input().split())x-=1y-=1E[x].append(y)E[y].append(x)A=list(map(int,input().split()))DIS=[-1]*NDIS[0]=0Q=[0]while Q:x=Q.pop()for to in E[x]:if DIS[to]==-1:DIS[to]=DIS[x]+1Q.append(to)XOR=0for i in range(N):if DIS[i]%2==1:XOR^=(A[i]%(K+1))if XOR!=0:print("K")else:print("P")