Road Network 2
Time limit5sMemory limit128 MB
Count the labeled trees that realize a prescribed degree sequence, or report that none exist, with n up to two million.
- Level
Medium6 of 10
- Topics
- Tree, Combinatorics, Math
- Solved
- No attempts yet
Problem
Byteland has cities, numbered through . Every road is bidirectional and connects two different cities. Between any two different cities there is exactly one path of roads that visits no city more than once. In other words, the road network is a tree with vertices and edges.
We want to build a road network in which exactly roads meet at city (that is, city has degree ). Many different networks may satisfy these conditions. Determine how many different road networks satisfy them. Cities carry distinct labels, so two networks are considered different whenever their sets of roads differ.
Input
The first line contains an integer (). The second line contains integers () separated by spaces, where is the degree of city .
Output
If no road network satisfies the conditions, print BRAK (Polish for 'none') on the only line. Otherwise, print the number of different road networks that satisfy the conditions, modulo 1,000,000,007.
Hint
