atcoder#ARC155F. [ARC155F] Directable as Desired
[ARC155F] Directable as Desired
Score : points
Problem Statement
You are given a sequence of non-negative integers: .
Find the number of labeled trees with vertices numbered to that satisfy the following condition, modulo .
- There is a way to direct the edges so that the outdegree of each vertex is .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
4
0 1 0 2
5
Below are the five trees that satisfy the condition, directed in a desired way.
5
0 1 1 1 1
125
15
0 0 0 0 0 0 0 1 1 1 1 1 2 3 4
63282877