#P10881. 「KDOI-07」能量场

    ID: 10883 远端评测题 5000ms 2048MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP2024洛谷原创O2优化组合数学线性代数

「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 (180+eps)(180+\mathrm{eps})^\circ angle.

Problem Description

Little K has nn energy fields. The ii-th energy field stores aia_i units of energy.

Little K builds nn 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 nn 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 [0,998244353)[0,998244353), you only need to output the total satisfaction modulo 998244353998244353.

Two ways of building pipelines are different if and only if there exists at least one pipeline connecting energy fields i,ji,j that appears in exactly one of the two ways.


[Formal Statement]

There is a complete graph G(V,E)G(V,E) with nn vertices. Each vertex has a weight aia_i. The edge weight between vertices i,ji,j is wi,j=ai+ajw_{i,j}=a_i+a_j.

Define a connected subgraph G(V,E)G'(V,E') where the weight of EEE'\subseteq E is eEwe\prod_{e\in E'}w_e. Note that the vertex set of the subgraph is the full set VV.

Compute the sum of the weights of all unicyclic graphs (connected graphs with exactly one cycle) among the connected subgraphs of G(V,E)G(V,E), modulo 998244353998244353.

A unicyclic graph must have no multiple edges and no self-loops.

Input Format

The first line contains a positive integer nn, denoting the number of energy fields.

The second line contains nn non-negative integers aia_i, denoting the energy stored in the ii-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 998244353998244353.

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 (1,2),(1,3),(2,3)(1,2),(1,3),(2,3) are 3,4,53,4,5 respectively, and their product is 6060.

Constraints

This problem uses bundled testdata.

Subtask\mathrm{Subtask} nn\leq Special Property Score
11 33 11
22 77 44
33 2424 \checkmark 55
44 1212 1010
55 1818
66 2020 55
77 2323
88 2424 3030
99 5050 1515
1010 200200 55
1111 500500
1212 10001000

Special property: it is guaranteed that i[1,n],ai=499122177\forall i\in[1,n],a_i=499122177.

For all testdata, it is guaranteed that 3n10003\leq n\leq 1000 and 0ai<9982443530\leq a_i<998244353.

Translated by ChatGPT 5