#P17461. [GESP202609 八级] 生成树计数

[GESP202609 八级] 生成树计数

Problem Description

Given an undirected connected graph GG with nn vertices and mm edges, the vertices are numbered 1,2,…,n1,2,\ldots,n in order. GG has the following special properties:

  • Each edge in GG belongs to at most one simple cycle.
  • GG has no multiple edges or self-loops.

A simple cycle means a cycle in which all vertices are distinct, and no edge is repeated.

Please find the number of different spanning trees of GG. Two spanning trees are different if and only if there exists an edge that appears in one spanning tree but not in the other.

Since the answer may be very large, you only need to output the result modulo 998244353998244353.

Input Format

The first line contains two positive integers n,mn,m, representing the number of vertices and the number of edges of GG, respectively.

In the next mm lines, each line contains two integers ui,viu_i,v_i, representing an undirected edge connecting vertices ui,viu_i,v_i.

Output Format

Output one line with one integer, representing the number of different spanning trees of GG modulo 998244353998244353.

7 8
1 2
2 3
3 1
3 4
4 5
5 6
6 7
7 4
12
5 4
1 2
1 3
2 4
2 5
1

Hint

For 40%40\% of the testdata, it is guaranteed that 1≤n≤81\le n\le 8 and 1≤m≤101\le m\le 10.

For 60%60\% of the testdata, it is guaranteed that 1≤n≤20001\le n\le 2000 and 1≤m≤20001\le m\le 2000.

For all testdata, it is guaranteed that 1≤n≤1051\le n\le 10^5, 1≤m≤1051\le m\le 10^5, and 1≤ui,vi≤n1\le u_i,v_i\le n.

Translated by ChatGPT 5