結果
問題 |
No.2726 Rooted Tree Nim
|
ユーザー |
|
提出日時 | 2024-05-08 19:56:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 210 ms / 2,000 ms |
コード長 | 980 bytes |
コンパイル時間 | 4,408 ms |
コンパイル使用メモリ | 255,864 KB |
最終ジャッジ日時 | 2025-02-21 11:49:20 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 |
ソースコード
#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; } int x = 0; for(int i = 0;i<N;i++){ if(depth[i]%2==1){ x ^= A[i]; } } sort(depthxor.begin(),depthxor.end()); if(x==0){ cout<<"P"<<endl; }else{ cout<<"K"<<endl; } } signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin >> T; for(int t= 0;t<T;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]; if(t==23)cerr<<N<<endl; solve(); } }