#P10881. 「KDOI-07」能量场
「KDOI-07」能量场
Background
In the year 4202, Little K, a gaLaxy enGineer Master who has been working for 3143 days, built an outpost on planet OIPA115 in the XS41 galaxy to help humans explore the unknown. There, he set up some energy fields. He originally planned to use some pawns (zu, 卒) to transport energy, but after two red pawns under his control collided and lost all their energy, he decided that he should instead connect them with energy pipelines, and make the energy pipelines form a angle.
Problem Description
Little K has energy fields. The -th energy field stores units of energy.
Little K builds distinct undirected energy pipelines between the energy fields, so that all energy fields are connected to each other (i.e., the resulting graph is connected).
For an energy pipeline, its energy level is the sum of the energies of the two energy fields at its ends.
Little K’s satisfaction for a set of distinct energy pipelines is the product of the energy levels of all pipelines.
Now Little K wants to know: among all different valid ways to build the energy pipelines, what is the total sum of satisfaction values? Since Little K’s satisfaction is an integer in , you only need to output the total satisfaction modulo .
Two ways of building pipelines are different if and only if there exists at least one pipeline connecting energy fields that appears in exactly one of the two ways.
[Formal Statement]
There is a complete graph with vertices. Each vertex has a weight . The edge weight between vertices is .
Define a connected subgraph where the weight of is . Note that the vertex set of the subgraph is the full set .
Compute the sum of the weights of all unicyclic graphs (connected graphs with exactly one cycle) among the connected subgraphs of , modulo .
A unicyclic graph must have no multiple edges and no self-loops.
Input Format
The first line contains a positive integer , denoting the number of energy fields.
The second line contains non-negative integers , denoting the energy stored in the -th energy field.
Output Format
One line containing a non-negative integer, denoting the total sum of satisfaction values over all different ways to build the energy pipelines, modulo .
3
1 2 3
60
4
1 2 3 4
8629
7
1 9 1 9 8 1 0
311816897
16
2 0 0 9 0 2 2 8 2 0 0 9 0 8 1 5
871736512
Hint
Sample Explanation 1
The only possible unicyclic form is a 3-vertex cycle. The edge weights of cycle edges are respectively, and their product is .
Constraints
This problem uses bundled testdata.
| Special Property | Score | ||
|---|---|---|---|
Special property: it is guaranteed that .
For all testdata, it is guaranteed that and .
Translated by ChatGPT 5