結果

問題 No.2726 Rooted Tree Nim
ユーザー KudeKude
提出日時 2024-04-12 22:12:52
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 4,079 ms
コンパイル使用メモリ 302,516 KB
実行使用メモリ 20,252 KB
最終ジャッジ日時 2024-04-12 22:13:07
合計ジャッジ時間 6,845 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 69 ms
6,812 KB
testcase_02 AC 121 ms
7,424 KB
testcase_03 AC 162 ms
20,252 KB
testcase_04 AC 160 ms
20,120 KB
testcase_05 AC 99 ms
15,920 KB
testcase_06 AC 98 ms
15,928 KB
testcase_07 AC 114 ms
15,952 KB
testcase_08 AC 117 ms
16,072 KB
testcase_09 AC 84 ms
6,944 KB
testcase_10 AC 87 ms
6,944 KB
testcase_11 AC 87 ms
7,680 KB
testcase_12 AC 129 ms
14,684 KB
testcase_13 AC 93 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    VVI to(n);
    rep(_, n - 1) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      to[u].emplace_back(v);
      to[v].emplace_back(u);
    }
    VI a(n);
    rep(i, n) cin >> a[i];
    int g = 0;
    auto dfs = [&](auto&& self, int u, int p, int d) -> void {
      if (d) g ^= a[u] % (k + 1);
      for (int v : to[u]) if (v != p) self(self, v, u, d ^ 1);
    };
    dfs(dfs, 0, -1, 0);
    cout << "PK"[g > 0] << '\n';
  }
}
0