A Tree Problem

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 0.6s
Memory limit: 162M

Problem types

Count the number of distinct spanning trees that exist on N labeled vertices, given that some of these vertices are restricted in their degree.

Constraints

1 \le N \le 1000

In test data worth 30% of marks, you may assume N \le 300.

Input Specification

The first line contains a single positive integer, N.

Each of the next N lines contains a single integer, d_i. If d_i is -1, then there is no degree restriction on vertex i. Otherwise, vertex i must have degree d_i.

Output Specification

Output the number of distinct spanning trees.

Sample Input

3
-1
-1
1

Sample Output

2

Comments


  • 13
    bqi343  commented on May 19, 2019, 9:52 a.m.

    Just read the formula at the end of this link.