#P6017. Counting Cactus Degree Sequences
Counting Cactus Degree Sequences
Counting Cactus Degree Sequences
We call a edge cactus any simple connected undirected graph in which every edge belongs to at most one simple cycle. For a graph with n vertices (numbered 1 through n) the degree sequence is defined as an array of length n where the i‑th element is the degree of vertex i.
Given two integers n and m, consider all edge cactus graphs on n vertices and m edges. Two graphs may yield the same degree sequence. Your task is to determine how many distinct degree sequences can be obtained from such graphs. Output the answer modulo \(998244353\).
If there is no valid edge cactus with the given parameters, print 0.
Note. It is known that any simple graph on n vertices has maximum degree at most n-1. Moreover, a well known necessary condition for the existence of a connected graph is that m \ge n-1 and for an edge cactus one can prove that \[ n-1 \le m \le n-1+\left\lfloor\frac{n-1}{2}\right\rfloor. \] Any degree sequence \(d_1,d_2,\dots,d_n\) coming from a cactus must satisfy \[ 1 \le d_i \le n-1 \quad\text{for } 1\le i\le n,\qquad \text{and}\qquad \sum_{i=1}^{n} d_i=2m. \] It turns out that every sequence of n numbers in the range [1, n-1] with sum \(2m\) is realizable by some cactus (and different cactus graphs might yield the same sequence). Thus the answer to the problem is equal to the number of solutions to
[ d_1+d_2+\cdots+d_n=2m, \quad 1\le d_i\le n-1 \text{ for } 1\le i\le n, ]
computed modulo (998244353>.
inputFormat
The input consists of a single line containing two space‐separated integers n and m (with n \(\ge\) 1).
Note that when n = 1 a valid cactus exists only if m = 0.
outputFormat
Output a single integer — the number of distinct degree sequences of an edge cactus with n vertices and m edges, modulo \(998244353\). If no valid cactus exists, output 0.
sample
3 2
3