atcoder#ARC121E. [ARC121E] Directed Tree
[ARC121E] Directed Tree
Score : points
Problem Statement
Given is a directed tree with vertices numbered through .
Vertex is the root of the tree. For each integer such that , there is a directed edge from Vertex to .
Let be the permutation of , and be the -th element of .
Among the sequences that can be , find the number of sequences that satisfy the following condition, modulo .
- Condition: For every integer such that , Vertex is unreachable from Vertex by traversing one or more edges.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of sequences among the permutations of that satisfy the condition in Problem Statement, modulo .
4
1 1 3
4
30
1 1 3 1 5 1 1 1 8 9 7 3 11 11 15 14 4 10 11 12 1 10 13 11 7 23 8 12 18
746746186
- Remember to print the count modulo .