結果

問題 No.2726 Rooted Tree Nim
コンテスト
ユーザー akua
提出日時 2025-11-27 23:02:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 2,182 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 130,960 KB
実行使用メモリ 22,828 KB
最終ジャッジ日時 2025-11-27 23:02:12
合計ジャッジ時間 6,262 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
#include <functional>
#include<unordered_map>
#include <random>
#include<bitset>
#include<cassert>
#include<chrono>
//#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vi>;
using P=pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define repi(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define all(x) (x).begin(),(x).end()
#define arr(x) (x).rbegin(),(x).rend()

template<typename T,typename S> bool chmin(T&a,const S&b){
    return a>b?a=b,1:0;
}
template<typename T,typename S> bool chmax(T&a,const S&b){
    return a<b?a=b,1:0;
}


ll pow_pow(ll x, ll n, ll mod) {
   if(n == 0) return 1;
   x %= mod;
   ll res = pow_pow(x * x % mod, n / 2, mod);
   if(n & 1) res = res * x % mod;
   return res;
}

const ll inf=4e18;
void solve(int test){
    int n,k; cin >> n >> k;
    vvi g(n);
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vi a(n);
    rep(i,n)cin >> a[i];
    int grad=0;
    auto dfs=[&](auto dfs,int v,int p,int d)->void{
        if(d){
            grad^=a[v]%(k+1);
        }
        for(auto u:g[v]){
            if(u==p)continue;
            dfs(dfs,u,v,d^1);
        }
    };
    dfs(dfs,0,-1,0);
    if(grad){
        cout << "K" << endl;
    }
    else {
        cout << "P" << endl;
    }




}
int main(){
    int t=1; cin >> t;
    rep(test,t)solve(test);
}




0