Erase Nodes
Time limit7sMemory limit512 MB
Nodes of a connected graph with n nodes and n edges are removed in random order; find the expected number of BFS updates, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Probability, Graph, Tree, Divide and conquer
- Solved
- No attempts yet
Statement
Bob's job is to maintain a network, which can be represented as a connected graph having nodes and undirected edges. Now he has to close the entire network.
In the beginning, all nodes are active. During the closing process, he repeatedly selects one active node and inactivates it until no active node remains. Each active node has a table that stores the connectivity information from that node to every other active node. When a node is inactivated, every active node (including itself) that could reach must update its table. Each update may change several records, since one inactivation can split a connected component into several smaller components, but the cost of each update is almost the same: running a breadth-first search from .
A bad order makes the number of updates large. Bob does not know how to find a good order, so he selects one active node uniformly at random at each step. Find the expected number of updates.
To avoid precision issues, if the answer is an irreducible fraction , report the minimum non-negative integer such that . For example, and .
Input
The input contains several test cases. The first line contains an integer , the number of test cases. Each test case begins with an integer . Each of the following lines contains two integers and , representing an edge between the -th node and the -th node.
Output
For each test case, output a line containing "Case #x: y", where is the test case number starting from 1, and is the answer to that test case.
Constraints
- The sum of over all test cases does not exceed .
- The edges of each test case are distinct. There are no multiple edges.