Cactus Eater
Time limit2sMemory limit512 MB
Given a cactus, find the expected total energy released when a random vertex is repeatedly eaten and each remaining component is processed, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Graph, DFS, Dynamic programming, Probability
- Solved
- No attempts yet
Statement
As is well known, a cactus is a connected undirected graph without loops or multiple edges, in which every edge belongs to at most one simple cycle.
A microorganism called cactofagi, the cactus eater, was recently discovered. When it lands on a connected component, it does the following:
- It releases joules of energy, where is the number of vertices in the component.
- It chooses a random vertex in the component and eats it along with all edges incident to it.
- It moves to every connected component that remains.
Find the expected total energy released when the microorganism lands on a given cactus and the cactus is fully destroyed.
Input
The first line contains two integers and , the number of vertices and edges of the cactus (; ).
Each of the next lines contains two integers and , the vertices joined by an edge (). It is guaranteed that the given graph is a cactus.
Output
It can be shown that the answer is a rational number. Write it as an irreducible fraction and print the value of .
Hint
In the second example the answer is 13.6, or as an irreducible fraction.