結果

問題 No.2726 Rooted Tree Nim
ユーザー GGanariGGanari
提出日時 2024-04-12 23:03:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 1,127 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 198,788 KB
実行使用メモリ 30,560 KB
最終ジャッジ日時 2024-04-12 23:04:04
合計ジャッジ時間 5,183 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 68 ms
6,944 KB
testcase_02 AC 108 ms
7,600 KB
testcase_03 AC 228 ms
30,560 KB
testcase_04 AC 210 ms
30,452 KB
testcase_05 AC 98 ms
15,792 KB
testcase_06 AC 102 ms
15,796 KB
testcase_07 AC 131 ms
16,164 KB
testcase_08 AC 126 ms
16,184 KB
testcase_09 AC 92 ms
6,944 KB
testcase_10 AC 98 ms
6,940 KB
testcase_11 AC 97 ms
7,680 KB
testcase_12 AC 134 ms
14,712 KB
testcase_13 AC 94 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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