結果

問題 No.2726 Rooted Tree Nim
ユーザー FplusFplusFFplusFplusF
提出日時 2024-04-12 23:06:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,184 bytes
コンパイル時間 4,248 ms
コンパイル使用メモリ 282,952 KB
実行使用メモリ 25,040 KB
最終ジャッジ日時 2024-04-12 23:06:51
合計ジャッジ時間 7,426 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 65 ms
6,944 KB
testcase_02 AC 132 ms
8,320 KB
testcase_03 AC 201 ms
24,928 KB
testcase_04 AC 201 ms
25,040 KB
testcase_05 AC 125 ms
17,200 KB
testcase_06 AC 129 ms
17,204 KB
testcase_07 AC 155 ms
17,952 KB
testcase_08 AC 152 ms
18,272 KB
testcase_09 AC 95 ms
6,940 KB
testcase_10 AC 101 ms
7,056 KB
testcase_11 AC 101 ms
8,320 KB
testcase_12 AC 132 ms
16,392 KB
testcase_13 AC 100 ms
7,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
    }
}
0