Jungle Job

시간 제한1초메모리 제한1024 MB

요약
정점이 n개인 루트 트리에서 크기가 1부터 n까지인 연결된 정점 부분집합의 개수를 각각 1000000007로 나눈 나머지로 구한다.
난이도

보통10점 중 7점

유형
트리, 동적 계획법, DFS, 조합론
정답자
아직 제출이 없습니다

문제

Your local jungle is being taken over by monkeys! Trees are quickly being colonized by them! As a Brave Ape Pictures Collector, this is your chance of taking sooo many pictures of primates that for sure will amaze your colleagues.

In particular, each day, one new monkey discovers your favourite tree containing nn branches. From your long experience observing primates, you know two things. First, each branch of the tree only has room for a single monkey. Second, monkeys are very social animals and always stick together in groups, that is, the branches they occupy form a single connected component.

This particular invasive species of monkeys happens to be new to you and you have not yet learned to distinguish them from each other. Still you wonder: how many different pictures of the monkey colony could you take on each day, until the tree is full of monkeys?

As an example, consider the first sample case, visualized in Figure J.1. On the third day, there are four different pictures you can take of the monkey colony.

Figure J.1: Visualization of the first sample case on the third day. Branches are connected if they overlap (note the small gap between branches 11 and 22, and between branches 33 and 44).

Monkey image from freevector.com

Given the exact structure of your favourite tree, determine for each day from 11 to nn the number of different sets of branches the monkeys could occupy on that day, modulo 109+710^9+7.

입력

The input consists of:

  • One line with an integer nn (1≤n≤10001\leq n\leq 1000), the number of branches in the tree.
  • n−1n-1 lines, the iith of which (\(1\leq i\leq n-1\)) contains an integer p_ip\_i (0≤p_i\<i0\leq p\_i\<i), indicating that branch ii is connected to the upper end of branch p_ip\_i.

The branches are numbered from 00 to n−1n-1, inclusive. Branch 00 is connected to the roots of the tree and can also host a single monkey.

출력

Output nn integers. The kkth integer should be the number of connected subtrees that consist of exactly kk branches, modulo 109+710^9+7.

예제2

  1. 예제 1

    입력
    5
    0
    0
    1
    1
    
    예상 출력
    5
    4
    4
    3
    1
    
  2. 예제 2

    입력
    3
    0
    1
    
    예상 출력
    3
    2
    1