結果
問題 | No.2726 Rooted Tree Nim |
ユーザー |
👑 |
提出日時 | 2024-03-30 11:24:04 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,231 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 30,848 KB |
実行使用メモリ | 13,440 KB |
最終ジャッジ日時 | 2024-09-30 17:26:53 |
合計ジャッジ時間 | 2,087 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | AC * 3 WA * 10 |
ソースコード
#include <stdio.h>typedef struct Edge {struct Edge *next;int v;} edge;int solve(int N, int K, int X[], int Y[], int A[]){int i, u, w;static edge *adj[200001], e[400001], *p;for (u = 1; u <= N; u++) adj[u] = NULL;for (i = 1; i < N; i++) {u = X[i];w = Y[i];e[i*2].v = w;e[i*2+1].v = u;e[i*2].next = adj[u];e[i*2+1].next = adj[w];adj[u] = &(e[i*2]);adj[w] = &(e[i*2+1]);}int x = 0, flag = 0;static int depth[200001], q[200001], head, tail;for (u = 1; u <= N; u++) depth[u] = -1;depth[1] = 0;q[0] = 1;for (head = 0, tail = 1; head < tail; head++) {u = q[head];if (depth[u] == 1) x ^= A[u] % (K + 1);else if (A[u] % (K + 1) != 0) flag = 1;for (p = adj[u]; p != NULL; p = p->next) {w = p->v;if (depth[w] < 0) {depth[w] = depth[u] + 1;q[tail++] = w;}}}if (x == 0 && flag == 0) return 0;else return 1;}int main(){int T, i, N, K, X[200001], Y[200001], A[200001];scanf("%d", &T);while (T--) {scanf("%d %d", &N, &K);for (i = 1; i < N; i++) scanf("%d %d", &(X[i]), &(Y[i]));for (i = 1; i <= N; i++) scanf("%d", &(A[i]));if (solve(N, K, X, Y, A) != 0) printf("K\n");else printf("P\n");}fflush(stdout);return 0;}