結果

問題 No.2726 Rooted Tree Nim
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-12 22:08:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 2,603 ms
コンパイル使用メモリ 203,268 KB
実行使用メモリ 23,252 KB
最終ジャッジ日時 2024-04-12 22:08:41
合計ジャッジ時間 5,806 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 204 ms
6,820 KB
testcase_02 AC 112 ms
7,296 KB
testcase_03 AC 186 ms
23,136 KB
testcase_04 AC 193 ms
23,252 KB
testcase_05 AC 117 ms
15,716 KB
testcase_06 AC 118 ms
15,692 KB
testcase_07 AC 126 ms
16,036 KB
testcase_08 AC 132 ms
16,204 KB
testcase_09 AC 94 ms
6,940 KB
testcase_10 AC 94 ms
6,940 KB
testcase_11 AC 101 ms
7,680 KB
testcase_12 AC 131 ms
14,484 KB
testcase_13 AC 97 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T; cin >> T;
    while(T--){
        int N,K; cin >> N >> K;
        vector<vector<int>> Graph(N);
        for(int i=0; i<N-1; i++){
            int u,v; cin >> u >> v;
            u--; v--;
            Graph.at(u).push_back(v);
            Graph.at(v).push_back(u);
        }
        vector<int> A(N);
        for(auto &a : A) cin >> a;

        int Xor = 0; K++;
    auto dfs = [&](auto dfs,int pos,int back,int d) -> void {
        Xor ^= d%2 * (A.at(pos)%K);
        for(auto to : Graph.at(pos)){
            if(to == back) continue;
            dfs(dfs,to,pos,d+1);
        }
    };
        dfs(dfs,0,-1,0);
        if(Xor) cout << "K" << endl;
        else cout << "P" << endl;
    }
}
0