結果

問題 No.2726 Rooted Tree Nim
ユーザー rikein12rikein12
提出日時 2024-04-12 22:41:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 588 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,576 KB
実行使用メモリ 141,668 KB
最終ジャッジ日時 2024-04-12 22:41:52
合計ジャッジ時間 7,816 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,052 KB
testcase_01 AC 558 ms
78,696 KB
testcase_02 AC 437 ms
104,440 KB
testcase_03 AC 513 ms
130,704 KB
testcase_04 AC 560 ms
130,484 KB
testcase_05 AC 442 ms
136,164 KB
testcase_06 AC 422 ms
136,328 KB
testcase_07 AC 588 ms
141,668 KB
testcase_08 AC 471 ms
141,376 KB
testcase_09 AC 373 ms
103,744 KB
testcase_10 AC 394 ms
107,156 KB
testcase_11 AC 447 ms
106,176 KB
testcase_12 AC 474 ms
135,948 KB
testcase_13 AC 391 ms
103,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def BFS(vi, e_list):
    N = len(e_list)
    INF = 10**9

    Q = deque([vi])

    min_path_list = [INF]*N #change
    min_path_list[vi] = 0

    while len(Q)>0:
        v = Q.pop()
        for v1 in e_list[v]:
            if min_path_list[v1] >= INF:
                Q.appendleft(v1)
                min_path_list[v1] = min_path_list[v]+1 #change
    return min_path_list

def solve():
    N,K = list(map(int,input().split()))
    e_list = [[] for i in range(N)]
    for i in range(N-1):
        x,y = list(map(int,input().split()))
        x -= 1
        y -= 1
        e_list[x].append(y)
        e_list[y].append(x)
    A = list(map(int,input().split()))
    min_path_list = BFS(0, e_list)
    B = []
    x = 0
    for a, d in zip(A, min_path_list):
        if d%2==1:
            x ^= (a%(K+1))
    if x==0:
        print("P")
    else:
        print("K")

T = int(input())

for i in range(T):
    solve()
0