結果
| 問題 |
No.2726 Rooted Tree Nim
|
| コンテスト | |
| ユーザー |
ニックネーム
|
| 提出日時 | 2024-04-12 22:25:45 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,538 ms / 2,000 ms |
| コード長 | 511 bytes |
| コンパイル時間 | 93 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 89,200 KB |
| 最終ジャッジ日時 | 2024-10-02 23:27:41 |
| 合計ジャッジ時間 | 16,208 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
from sys import setrecursionlimit
setrecursionlimit(10**6)
for _ in range(int(input())):
n,k = map(int,input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
x,y = map(int,input().split())
adj[x-1].append(y-1); adj[y-1].append(x-1)
a = list(map(int,input().split()))
def dfs(v,p):
for c in adj[v]:
if c!=p: f[c] = f[v]^1; dfs(c,v)
f = [0]*n; dfs(0,-1); z = 0
for u,v in zip(f,a):
if u: z ^= v%(k+1)
print("K" if z else "P")
ニックネーム