結果
問題 | No.2841 Leaf Eater |
ユーザー |
|
提出日時 | 2024-08-09 22:42:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 172 ms / 2,000 ms |
コード長 | 1,024 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 99,584 KB |
最終ジャッジ日時 | 2024-08-09 22:42:08 |
合計ジャッジ時間 | 4,634 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 23 |
ソースコード
import sys,time from itertools import permutations from heapq import heappop,heappush from collections import deque import random import bisect input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def solve(N,parent): child = [[] for v in range(N)] for v in range(1,N): child[parent[v]].append(v) dp0 = [""] * N dp1 = [""] * N for v in range(N)[::-1]: if len(child[v]) == 0: dp0[v] = "Second" dp1[v] = "First" elif len(child[v]) == 1: c = child[v][0] dp0[v] = dp1[c] dp1[v] = dp0[c] else: flg = False for c in child[v]: if dp1[c] == "First": flg = True dp0[v] = "First" if flg else "Second" dp1[v] = dp0[v] return dp0[0] for _ in range(int(input())): N = int(input()) parent = [-1] + [int(p)-1 for p in input().split()] print(solve(N,parent))