#P9535. [YsOI2023] 连通图计数
[YsOI2023] 连通图计数
Background
A polynomial problem for Ysuperman’s template testing.
[Data removed]
Problem Description
How many undirected simple connected graphs with vertices and edges are there, with no self-loops and no multiple edges, such that after deleting the vertex numbered , the undirected graph is split into connected components. In particular, we guarantee , and the answer is not .
Output the answer modulo .
Input Format
The first line contains two integers .
The second line contains integers, where the -th integer is .
Output Format
Output one integer per line, representing the result of the answer modulo .
4 4
2 1 1 1
3
4 5
1 1 1 1
6
5 6
1 1 2 1 1
27
6 6
1 2 3 1 1 1
30
6 5
2 1 1 1 1 4
4
8 7
1 1 3 1 2 2 2 2
360
8 8
1 1 1 1 2 2 2 2
2520
8 9
1 1 1 1 1 1 2 3
9240
10 11
1 1 1 4 2 2 2 1 1 1
105840
12 13
1 1 1 1 1 1 1 1 1 1 1 1
518269694
Hint
Explanation for Sample 1
There are three possible graphs. The four edges in each case are:
- .
- .
- .
Constraints
| Test Point ID | Special Property | |
|---|---|---|
| None | ||
| , | ||
| None | ||
| , | ||
| None |
For all testdata, it holds that , , , , and the answer is guaranteed to be non-zero.
Translated by ChatGPT 5