結果
| 問題 | No.2726 Rooted Tree Nim |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-13 15:27:58 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 2,000 ms |
| コード長 | 2,840 bytes |
| 記録 | |
| コンパイル時間 | 1,793 ms |
| コンパイル使用メモリ | 232,524 KB |
| 実行使用メモリ | 21,376 KB |
| 最終ジャッジ日時 | 2026-06-13 15:28:07 |
| 合計ジャッジ時間 | 5,614 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // cmathライブラリをインクルード
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <random>
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Yout cout << "Yes" << '\n'
#define Nout cout << "No" << '\n'
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
// #define _LIBCPP_DEBUG 0と書く必要があります。
const ll mod = 998244353;
const ll mod2 = (long long)1000000007;
const ll INF = (long long)2e18;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
// const vector<int> dx = {1, 1, 1, 0, -1, -1, -1, 0};
// const vector<int> dy = {1, 0, -1, -1, -1, 0, 1, 1};
// const vector<int> dx = {1, -1, 1, -1};
// const vector<int> dy = {1, 1, -1, -1};
template <class T> void li(T a) {
for (auto i : a) {
cout << i << ' ';
}
cout << endl;
}
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;
}
bool ch(ll l, ll r, ll x) { return l <= x and x < r; }
bool chch(ll h, ll w, ll x, ll y) { return ch(0, h, x) and ch(0, w, y); }
void solve() {
ll n, k;
cin >> n >> k;
vector<vector<ll>> g(n);
rep(i, n - 1) {
ll u, v;
cin >> u >> v;
u--;
v--;
g[u].pb(v);
g[v].pb(u);
}
vector<ll> dist(n, -1);
dist[0] = 0;
queue<ll> todo;
todo.push(0);
while (!todo.empty()) {
ll t = todo.front();
todo.pop();
for (auto i : g[t]) {
if (dist[i] == -1) {
dist[i] = dist[t] + 1;
todo.push(i);
}
}
}
vector<ll> a(n);
//li(dist);
rep(i, n) { cin >> a[i]; }
ll s = 0;
rep(i, n) {
if (dist[i] % 2 == 1) {
s ^= a[i]%(k+1);
}
}
if (s != 0) {
cout << "K" << endl;
} else {
cout << "P" << endl;
}
}
void test() {}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll t = 1;
cin >> t;
rep(i, t) { solve(); }
// test();
}