結果
問題 | No.2726 Rooted Tree Nim |
ユーザー | MasKoaTS |
提出日時 | 2024-01-02 21:18:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 373 ms / 2,000 ms |
コード長 | 1,540 bytes |
コンパイル時間 | 412 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 167,108 KB |
最終ジャッジ日時 | 2024-09-27 17:53:36 |
合計ジャッジ時間 | 7,085 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 107 ms
86,164 KB |
testcase_01 | AC | 274 ms
93,348 KB |
testcase_02 | AC | 292 ms
122,292 KB |
testcase_03 | AC | 364 ms
151,448 KB |
testcase_04 | AC | 373 ms
151,488 KB |
testcase_05 | AC | 353 ms
167,108 KB |
testcase_06 | AC | 349 ms
166,404 KB |
testcase_07 | AC | 336 ms
151,360 KB |
testcase_08 | AC | 373 ms
154,996 KB |
testcase_09 | AC | 314 ms
118,816 KB |
testcase_10 | AC | 303 ms
128,652 KB |
testcase_11 | AC | 321 ms
129,980 KB |
testcase_12 | AC | 345 ms
147,772 KB |
testcase_13 | AC | 294 ms
121,036 KB |
ソースコード
import itertools as iter import collections as coll import heapq as hq import bisect as bis from decimal import Decimal as dec from functools import cmp_to_key import math import sys #import pypyjit #pypyjit.set_param('max_unroll_recursion=-1') sys.setrecursionlimit(10 ** 6) inp = sys.stdin.readline input = lambda : inp()[:-1] getN = lambda : int(inp()) getNs = lambda : map(int, inp().split()) getList = lambda : list(map(int, inp().split())) getStrs = lambda n : [input() for _ in [0] * n] getEdges = lambda n : [[x - 1 for x in getNs()] for _ in [0] * n] getWEdges = lambda n : [[x - (i < 2) for i, x in enumerate(getNs())] for _ in [0] * n] def yexit(): print("Yes"); exit(0) def nexit(): print("No"); exit(0) pi = 3.141592653589793 mod = 1000000007 MOD = 998244353 INF = 4611686018427387903 dxs = [1, 0, -1, 0]; dys = [0, 1, 0, -1] #di = coll.defaultdict(int) """ Main Code """ def solve(N, K, edges, a): graph = [[] for _ in [0] * N] for x, y in edges: graph[x].append(y) graph[y].append(x) depth = [-1] * N depth[0] = 0 stk = [0] while(stk): v = stk.pop() nd = depth[v] + 1 for nv in graph[v]: if(depth[nv] != -1): continue depth[nv] = nd stk.append(nv) lis = [i for i in range(N) if(depth[i] & 1)] g = 0 for k in lis: g ^= a[k] % (K + 1) return 'K' if(g) else 'P' for _ in [0] * getN(): N, K = getNs() edges = getEdges(N - 1) a = getList() print(solve(N, K, edges, a))