結果
| 問題 |
No.2726 Rooted Tree Nim
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2024-04-12 23:06:43 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 170 ms / 2,000 ms |
| コード長 | 1,184 bytes |
| コンパイル時間 | 2,943 ms |
| コンパイル使用メモリ | 253,452 KB |
| 実行使用メモリ | 25,056 KB |
| 最終ジャッジ日時 | 2024-10-02 23:44:27 |
| 合計ジャッジ時間 | 5,485 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> inline bool chmin(T &a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T &a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
ll n,k,d=0,ans=0;
vector<ll> a;
vector<vector<ll>> g;
void dfs(ll x,ll p){
if(d%2==1) ans^=a[x]%(k+1);
for(auto i:g[x]){
if(i==p) continue;
d++;
dfs(i,x);
d--;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll t;
cin >> t;
while(t--){
cin >> n >> k;
g.assign(n,{});
rep(i,n-1){
ll x,y;
cin >> x >> y;
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
a.assign(n,0);
rep(i,n) cin >> a[i];
d=0;
ans=0;
dfs(0,-1);
if(ans==0) cout << "P\n";
else cout << "K\n";
}
}
FplusFplusF