Counting Cactus
Time limit2sMemory limit512 MB
Count the edge subsets of a graph with at most 13 vertices that form a connected cactus, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Dynamic programming, Graph
- Solved
- No attempts yet
Problem
NEERC has featured several problems about cactuses: connected undirected graphs in which every edge belongs to at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. The picture below shows a cactus from a NEERC 2007 problem.

Dreamoon has an undirected graph. He wants to know how many subgraphs (subsets of edges) of his graph are cactuses. Can you find this value modulo 998 244 353?
Input
The first line contains two integers and , the number of vertices and edges in the graph. (, )
The next lines describe the edges. The -th line contains two integers and , denoting an edge between vertices and . (, ) No edge appears more than once.
Output
Output one integer: the number of cactus subgraphs, modulo 998 244 353.
Hint
Sorry, Dreamoon.