結果
問題 |
No.2726 Rooted Tree Nim
|
ユーザー |
|
提出日時 | 2024-05-08 19:36:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 918 bytes |
コンパイル時間 | 4,229 ms |
コンパイル使用メモリ | 253,308 KB |
最終ジャッジ日時 | 2025-02-21 11:49:01 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 5 WA * 8 |
ソースコード
#include<bits/stdc++.h> #include <iostream> using namespace std; #include<atcoder/all> using namespace atcoder; using ll = long long; int N,K; vector<vector<int>> G; vector<int> A; vector<int> depth; void dfs(int v,int p,int d){ depth[v] = d; for(int u:G[v]){ if(u==p) continue; dfs(u,v,d+1); } } void solve(){ depth = vector<int>(N,0); dfs(0,-1,0); vector<int> depthxor(N); for(int i = 0;i<N;i++){ A[i] %= K+1; } for(int i = 0;i<N;i++){ if(depth[i]%2==1){ depthxor[depth[i]] ^= A[i]; } } if(depthxor[1]==0){ cout<<"P"<<endl; }else{ cout<<"K"<<endl; } } signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin >> T; while(T--){ cin >> N >> K; G = vector<vector<int>>(N); A.resize(N); for(int i = 0;i<N-1;i++){ int u,v; cin >> u >> v; u--; v--; G[u].push_back(v); G[v].push_back(u); } for(int i = 0;i<N;i++) cin >> A[i]; solve(); } }