結果

問題 No.2726 Rooted Tree Nim
ユーザー kotatsugamekotatsugame
提出日時 2024-04-12 21:55:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 70,300 KB
実行使用メモリ 29,252 KB
最終ジャッジ日時 2024-04-12 21:55:33
合計ジャッジ時間 3,580 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,596 KB
testcase_01 AC 63 ms
9,484 KB
testcase_02 AC 120 ms
12,160 KB
testcase_03 AC 201 ms
29,252 KB
testcase_04 AC 204 ms
29,120 KB
testcase_05 AC 107 ms
17,420 KB
testcase_06 AC 108 ms
17,220 KB
testcase_07 AC 125 ms
17,848 KB
testcase_08 AC 131 ms
17,752 KB
testcase_09 AC 84 ms
13,384 KB
testcase_10 AC 86 ms
12,412 KB
testcase_11 AC 89 ms
13,152 KB
testcase_12 AC 130 ms
17,092 KB
testcase_13 AC 97 ms
12,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
int N,K;
vector<int>G[2<<17];
int A[2<<17];
int dfs(int u,int p,int d)
{
	int ret=0;
	if(d%2==1)ret^=A[u]%(K+1);
	for(int v:G[u])if(v!=p)ret^=dfs(v,u,d+1);
	return ret;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;cin>>T;
	for(;T--;)
	{
		cin>>N>>K;
		for(int i=0;i<N;i++)G[i].clear();
		for(int i=1;i<N;i++)
		{
			int u,v;cin>>u>>v;
			u--,v--;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		for(int i=0;i<N;i++)cin>>A[i];
		cout<<(dfs(0,-1,0)?"K\n":"P\n");
	}
}
0