#P10286. 「RiOI-03」A Journey to the Moonlight(加强版)
「RiOI-03」A Journey to the Moonlight(加强版)
Background
Compared with P9919, this problem has a larger Constraints range.
Problem Description
For a bipartite graph with vertices on the right side, define its weight as follows:
- Choose a matching scheme, and mark the first matched right-side vertex. If no such vertex exists, then mark the first unmatched right-side vertex.
- Each time, randomly choose a permutation of . Stop when the unmatched right-side vertices and the marked vertex appear as a contiguous segment in the permutation in increasing label order.
- is the minimum value of the expected number of operations over all matching schemes.
Define this bipartite graph to be -valid if and only if:
- The degree of every left-side vertex is between and .
- There do not exist two different left-side vertices whose sets of adjacent vertices are identical.
Let be the sum of over all -valid bipartite graphs with right-side vertices, where left-side vertices are not distinguished.
Given , compute .
Input Format
The first line contains two positive integers .
The second line contains non-negative integers, representing .
Output Format
Output one non-negative integer, the answer.
2 1
1 1 1
15
3 2
1 1 1 1
40
12 1
1 1 4 5 1 4 1 9 1 9 8 1 0
721168027
Hint
By convention, a left-side vertex connected to right-side vertices numbered is denoted as .
[Sample 1 Explanation]
For , the answers are clearly .
For , the possible bipartite graphs are (represented by the tuple formed by the neighbors of each left-side vertex):
$\{(1),(2)\},\{(1,2),(2)\},\{(1,2),(1)\},\{(1,2),(1),(2)\}$
Graphs with the same expectation are grouped together. The answer is , so the output is .
[Sample 2 Explanation]
For , the answers are .
For , the possible bipartite graphs are (represented by the tuple formed by the neighbors of each left-side vertex):
The answer is $\dfrac61+\dfrac61\times3+\dfrac62\times3+\dfrac66=34$.
[Constraints]
For of the testdata, , , .
Translated by ChatGPT 5