#P5296. [北京省选集训2019] 生成树计数

    ID: 4240 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2019北京O2优化生成函数高斯消元

[北京省选集训2019] 生成树计数

Description

Little S has just learned about spanning trees. Being clever, he came up with a question:
Given a weighted undirected complete graph with nn vertices, find the sum of the kk-th powers of the weights of all spanning trees.
The weight of a tree is defined as the sum of the weights of all its edges.

Since he cannot solve it, you have to do it.
Because the answer may be very large, output the result modulo 998244353998244353.

Input Format

The first line contains two non-negative integers n,kn, k, as described above.
The next nn lines each contain nn integers, representing the adjacency matrix of this weighted undirected complete graph.
Let wi,jw_{i,j} denote the entry in row ii and column jj of the matrix, and it is guaranteed that:
wi,i=0w_{i,i} = 0, and wi,j=wj,iw_{i,j} = w_{j,i}.

Output Format

Output one line containing one integer, representing the answer modulo 998244353998244353.

3 1
0 0 1
0 0 1
1 1 0
4

Hint

Constraints:

For 20%20\% of the testdata: 1n51 \le n \le 5.
For another 10%10\% of the testdata: k=0k = 0.
For another 10%10\% of the testdata: k=1k = 1.
For 60%60\% of the testdata: 1n151 \le n \le 15.
For another 15%15\% of the testdata: 1k151 \le k \le 15.
For 100%100\% of the testdata: 1n301 \le n \le 30, 0k300 \le k \le 30, 0wi,j9982443520 \le w_{i,j} \le 998244352.

Note that 00=10^0 = 1.

Translated by ChatGPT 5