結果

問題 No.2726 Rooted Tree Nim
ユーザー 👑 hitonanodehitonanode
提出日時 2024-04-12 22:31:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 976 ms
コンパイル使用メモリ 94,640 KB
実行使用メモリ 20,072 KB
最終ジャッジ日時 2024-04-12 22:31:27
合計ジャッジ時間 3,955 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 72 ms
6,944 KB
testcase_02 AC 139 ms
7,296 KB
testcase_03 AC 183 ms
19,980 KB
testcase_04 AC 183 ms
20,072 KB
testcase_05 AC 104 ms
15,612 KB
testcase_06 AC 103 ms
15,792 KB
testcase_07 AC 124 ms
16,156 KB
testcase_08 AC 125 ms
16,248 KB
testcase_09 AC 89 ms
6,940 KB
testcase_10 AC 106 ms
6,940 KB
testcase_11 AC 115 ms
7,552 KB
testcase_12 AC 148 ms
14,648 KB
testcase_13 AC 92 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
    }
}
0