結果

問題 No.2841 Leaf Eater
ユーザー ygussanyygussany
提出日時 2024-08-03 19:16:17
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-08-03 19:16:21
合計ジャッジ時間 3,157 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 17 ms
5,376 KB
testcase_02 AC 17 ms
5,376 KB
testcase_03 AC 19 ms
5,376 KB
testcase_04 AC 19 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 23 ms
5,376 KB
testcase_07 AC 18 ms
5,376 KB
testcase_08 AC 20 ms
5,376 KB
testcase_09 AC 24 ms
7,936 KB
testcase_10 AC 24 ms
7,808 KB
testcase_11 AC 25 ms
7,772 KB
testcase_12 AC 24 ms
7,168 KB
testcase_13 AC 19 ms
5,376 KB
testcase_14 AC 22 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 21 ms
5,376 KB
testcase_17 AC 18 ms
5,376 KB
testcase_18 AC 18 ms
5,376 KB
testcase_19 AC 18 ms
5,376 KB
testcase_20 AC 18 ms
5,376 KB
testcase_21 AC 19 ms
5,376 KB
testcase_22 AC 18 ms
5,376 KB
testcase_23 AC 18 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct Edge {
	struct Edge *next;
	int v;
} edge;

int solve(int N, int par[])
{
	int u, w, flag;
	static int dp[200001];
	static edge *adj[200001], e[200001], *p;
	for (u = 1; u <= N; u++) adj[u] = NULL;
	for (w = 2; w <= N; w++) {
		u = par[w];
		e[w].v = w;
		e[w].next = adj[u];
		adj[u] = &(e[w]);
	}
	for (u = N; u >= 1; u--) {
		if (adj[u] == NULL) {
			dp[u] = 0;
			continue;
		} else if (adj[u]->next == NULL) {
			w = adj[u]->v;
			if (dp[w] <= 1) dp[u] = dp[w] ^ 1;
			else dp[u] = dp[w];
			continue;
		}
		for (p = adj[u], flag = 0; p != NULL; p = p->next) {
			w = p->v;
			if (dp[w] == 0) flag++;
		}
		if (flag > 0) return 1;
		dp[u] = 2;
	}
	if (dp[1] == 1) return 1;
	else return 0;
}

int main()
{
	int T, i, N, p[200001];
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &N);
		for (i = 2; i <= N; i++) scanf("%d", &(p[i]));
		if (solve(N, p) != 0) printf("First\n");
		else printf("Second\n");
	}
	fflush(stdout);
	return 0;
}
0