#P9535. [YsOI2023] 连通图计数

    ID: 10665 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>数学洛谷原创O2优化洛谷月赛

[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 n−1≤m≤n+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
1∼41\sim 4 m=n−1m=n-1 None
5∼65\sim 6 m=nm=n,n≤7n\le 7
7∼87\sim 8 m=nm=n ai=1a_i=1
9∼129\sim 12 None
13∼1413\sim 14 m=n+1m=n+1,n≤7n\le 7
15∼1615\sim 16 m=n+1m=n+1 ai=1a_i=1
17∼2017\sim 20 None

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

Translated by ChatGPT 5