#P2624. [HNOI2008] 明明的烦恼

[HNOI2008] 明明的烦恼

Description

Ever since Mingming learned about tree structures, he has become interested in unusual trees.

Given nodes labeled 11 to NN, and the final degrees of some nodes, you may add edges between any pair of nodes. How many trees can be formed whose degrees meet the given requirements?

Input Format

The first line contains a positive integer NN (0<N10000 < N \le 1000).

The next NN lines: the (i+1)(i+1)-th line contains a positive integer representing the degree DiD_i of the ii-th node. If the degree is unconstrained, input -1.

Output Format

Output a single positive integer on one line, the number of different trees that satisfy the requirements. If there is no solution, output 00.

3
1
-1
-1
2

Hint

The two trees are 1-2-3 and 1-3-2.

Translated by ChatGPT 5