結果
| 問題 |
No.2726 Rooted Tree Nim
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-12 23:03:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 270 ms / 2,000 ms |
| コード長 | 1,127 bytes |
| コンパイル時間 | 2,522 ms |
| コンパイル使用メモリ | 195,820 KB |
| 最終ジャッジ日時 | 2025-02-21 00:45:11 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
#define INF 1000000001LL
#define LNF 1000000000000000001LL
#define MOD 998244353LL
#define MAX 200001
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;
void dfs(int x, int par,vector<int> graph[], vector<int>&depth)
{
for(int y : graph[x])
{
if(y == par)
continue;
depth[y] = depth[x]+1;
dfs(y,x,graph,depth);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--)
{
int n,k;
cin >> n >> k;
vector<int> graph[n+1];
for(int i = 0; i<n-1; i++)
{
int a,b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<int> depth(n+1);
dfs(1,0,graph,depth);
int grundy = 0;
for(int i = 1; i<=n; i++)
{
int x;
cin >> x;
if(depth[i]&1)
grundy^=x%(k+1);
}
if(grundy)
cout << "K\n";
else
cout << "P\n";
}
return 0;
}