結果

問題 No.2726 Rooted Tree Nim
ユーザー inksamuraiinksamurai
提出日時 2024-04-12 23:17:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 2,710 ms
コンパイル使用メモリ 202,840 KB
実行使用メモリ 25,588 KB
最終ジャッジ日時 2024-04-12 23:17:21
合計ジャッジ時間 6,143 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 78 ms
6,944 KB
testcase_02 AC 135 ms
8,832 KB
testcase_03 AC 213 ms
25,572 KB
testcase_04 AC 211 ms
25,588 KB
testcase_05 AC 123 ms
18,868 KB
testcase_06 AC 119 ms
18,744 KB
testcase_07 AC 157 ms
19,548 KB
testcase_08 AC 143 ms
19,488 KB
testcase_09 AC 127 ms
7,168 KB
testcase_10 AC 144 ms
7,184 KB
testcase_11 AC 105 ms
8,832 KB
testcase_12 AC 181 ms
17,628 KB
testcase_13 AC 168 ms
7,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int) a.size())
#define vec(...) vector<__VA_ARGS__>
#define _49vEjP0 ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

void slv(){
	int n,k;
	cin>>n>>k;

	vec(vi) adj(n);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u-=1,v-=1;
		adj[u].pb(v),adj[v].pb(u);
	}

	vi a(n);
	rep(i,n){
		cin>>a[i];
	}

	vi dep(n);
	auto dfs=[&](auto self,int v,int par)->void{
		for(auto u:adj[v]){
			if(u==par) continue;
			dep[u]=dep[v]+1;
			self(self,u,v);
		}
	};
	dfs(dfs,0,-1);

	int sxor=0;
	rep(v,n){
		if(dep[v]%2){
			sxor^=(a[v]%(k+1));
		}
	}
	if(sxor==0){
		cout<<"P\n";
	}else{
		cout<<"K\n";
	}
}

signed main(){
_49vEjP0;
	int __t;
	cin>>__t;
	rep(cs,__t){
		slv();
	}
}
0