結果

問題 No.2726 Rooted Tree Nim
ユーザー 沙耶花沙耶花
提出日時 2024-04-12 23:13:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 4,632 ms
コンパイル使用メモリ 256,420 KB
実行使用メモリ 30,640 KB
最終ジャッジ日時 2024-04-12 23:13:20
合計ジャッジ時間 9,777 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 345 ms
6,940 KB
testcase_02 AC 244 ms
7,424 KB
testcase_03 AC 329 ms
30,640 KB
testcase_04 AC 325 ms
30,520 KB
testcase_05 AC 220 ms
15,772 KB
testcase_06 AC 233 ms
15,904 KB
testcase_07 AC 264 ms
16,192 KB
testcase_08 AC 269 ms
16,220 KB
testcase_09 AC 217 ms
6,944 KB
testcase_10 AC 221 ms
6,944 KB
testcase_11 AC 249 ms
7,552 KB
testcase_12 AC 299 ms
14,660 KB
testcase_13 AC 225 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

void dfs(vector<int> &d,vector<vector<int>> &E,int cv,int pv){
	if(pv==-1)d[cv] = 0;
	else d[cv] = d[pv] + 1;
	rep(i,E[cv].size()){
		int to  = E[cv][i];
		if(to==pv)continue;
		dfs(d,E,to,cv);
	}
}

int main(){
	
	int _t;
	cin>>_t;
	rep(_,_t){
		int n,K;
		cin>>n>>K;
		vector<vector<int>> E(n);
		rep(i,n-1){
			int x,y;
			cin>>x>>y;
			x--,y--;
			E[x].push_back(y);
			E[y].push_back(x);
		}
		vector<int> d(n);
		dfs(d,E,0,-1);
		long long cur = 0;
		rep(i,n){
			int a;
			cin>>a;
			if(d[i]%2==1){
				cur ^= a % (K+1);
				
			}
		}
		if(cur==0)cout<<"P"<<endl;
		else cout<<"K"<<endl;
	}
	
	return 0;
}
0