#P9535. [YsOI2023] 连通图计数

[YsOI2023] 连通图计数

Background

A polynomial problem for Ysuperman’s template testing.

[Data removed]

Problem Description

How many undirected simple connected graphs with nn vertices and mm edges are there, with no self-loops and no multiple edges, such that after deleting the vertex numbered ii, the undirected graph is split into aia_i connected components. In particular, we guarantee n1mn+1n-1 \le m \le n+1, and the answer is not 00.

Output the answer modulo 998,244,353998,244,353.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers, where the ii-th integer is aia_i.

Output Format

Output one integer per line, representing the result of the answer modulo 998,244,353998,244,353.

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:

  1. (1,2),(1,3),(1,4),(2,3)(1,2),(1,3),(1,4),(2,3).
  2. (1,2),(1,3),(1,4),(2,4)(1,2),(1,3),(1,4),(2,4).
  3. (1,2),(1,3),(1,4),(3,4)(1,2),(1,3),(1,4),(3,4).

Constraints

Test Point ID n,mn,m Special Property
141\sim 4 m=n1m=n-1 None
565\sim 6 m=nm=nn7n\le 7
787\sim 8 m=nm=n ai=1a_i=1
9129\sim 12 None
131413\sim 14 m=n+1m=n+1n7n\le 7
151615\sim 16 m=n+1m=n+1 ai=1a_i=1
172017\sim 20 None

For all testdata, it holds that 4n1054 \le n \le 10^5, n1mn+1n-1 \le m \le n+1, 1ai<n1 \le a_i < n, ni=1nai2n2n \le \sum_{i=1}^n a_i \le 2n-2, and the answer is guaranteed to be non-zero.

Translated by ChatGPT 5