結果
| 問題 |
No.2726 Rooted Tree Nim
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2024-04-12 23:13:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 371 ms / 2,000 ms |
| コード長 | 863 bytes |
| コンパイル時間 | 4,111 ms |
| コンパイル使用メモリ | 251,592 KB |
| 最終ジャッジ日時 | 2025-02-21 00:47:35 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#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;
}
沙耶花