結果
| 問題 |
No.2726 Rooted Tree Nim
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2024-04-12 22:31:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 161 ms / 2,000 ms |
| コード長 | 838 bytes |
| コンパイル時間 | 951 ms |
| コンパイル使用メモリ | 93,224 KB |
| 実行使用メモリ | 20,044 KB |
| 最終ジャッジ日時 | 2024-10-02 23:30:28 |
| 合計ジャッジ時間 | 3,404 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int N, K;
cin >> N >> K;
vector<vector<int>> to(N);
for (int e = 0; e < N - 1; ++e) {
int a, b;
cin >> a >> b;
--a, --b;
to.at(a).push_back(b);
to.at(b).push_back(a);
}
vector<int> A(N);
for (auto &a : A) cin >> a;
int gru = 0;
auto rec = [&](auto &&rec, int v, int p, int depth) -> void {
if (depth % 2) gru ^= A.at(v) % (K + 1);
for (auto u : to.at(v)) {
if (u != p) rec(rec, u, v, depth + 1);
}
};
rec(rec, 0, -1, 0);
cout << (gru ? 'K' : 'P') << '\n';
}
}
hitonanode