結果

問題 No.2726 Rooted Tree Nim
ユーザー ニックネームニックネーム
提出日時 2024-04-12 22:25:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,621 ms / 2,000 ms
コード長 511 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 89,076 KB
最終ジャッジ日時 2024-04-12 22:26:03
合計ジャッジ時間 17,196 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 1,621 ms
10,880 KB
testcase_02 AC 987 ms
30,484 KB
testcase_03 AC 1,516 ms
89,076 KB
testcase_04 AC 1,542 ms
88,984 KB
testcase_05 AC 1,130 ms
60,772 KB
testcase_06 AC 1,122 ms
60,900 KB
testcase_07 AC 1,294 ms
67,452 KB
testcase_08 AC 1,307 ms
69,608 KB
testcase_09 AC 949 ms
24,840 KB
testcase_10 AC 1,027 ms
24,608 KB
testcase_11 AC 1,035 ms
30,288 KB
testcase_12 AC 1,153 ms
61,476 KB
testcase_13 AC 942 ms
25,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0