#P14016. [ICPC 2024 Nanjing R] 拓扑
[ICPC 2024 Nanjing R] 拓扑
Description
You are given a tree consisting of vertices, rooted at vertex . It is guaranteed that every vertex has a smaller index than all of its children. A topological order of this tree is a permutation of that satisfies the following constraint: For all , vertex is not the parent of vertex .
For each , calculate the number of topological orders of the given tree satisfying , modulo .
Input Format
There is only one test case in each test file.
The first line contains an integer (), denoting the number of vertices of the tree.
The second line contains integers (), where is the parent of vertex .
Output Format
Output one line containing integers separated by a space, where is the number of topological orders satisfying , modulo .
4
1 1 2
3 2 1 2
9
1 1 2 2 3 3 4 5
672 420 180 160 152 108 120 170 210
Hint
For the first sample test case, all topological orders of the tree are , and . There are of them satisfying , of them satisfying , of them satisfying , and of them satisfying .
京公网安备 11011102002149号