409636: GYM103652 A Erase Nodes

Memory Limit:0 MB Time Limit:7 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Erase Nodestime limit per test7 secondsmemory limit per test256 mebibytesinputstandard inputoutputstandard output

Bob's job is to maintain a network, which can be represented as a connected graph having $$$n$$$ nodes and $$$n$$$ undirected edges, but now he has to close the entire network.

In the beginning, all nodes are active. During the processing of closing, he will repeatedly select one active node and inactivate it until there is no active node. However, each active node has a table that stores the connectivity information from this node to any other active node. When a node $$$u$$$ is inactivated, every active node $$$v$$$ (including $$$u$$$ itself) that used to be able to reach $$$u$$$ have to update its own table. Each update may change several records, as each inactivation can cut a connected component into several smaller components, but the cost of each update is almost the same — running a breadth-first search from $$$v$$$.

Now Bob is wondering in which order he should close these nodes because he knows if he operated these nodes in a bad order, the number of updates would be a bit large. He is not good at finding a good solution, so he chooses to randomly select one active node with equal probability at any time. Could you help him estimate the expected number of updates?

To avoid any precision issue, if the answer can be represented as an irreducible fraction $$$\frac{p}{q}$$$, then you are asked to report the minimum non-negative integer $$$r$$$ such that $$$q r \equiv p \pmod{998244353}$$$. For example, $$$6 \times 166374072 \equiv 79, 3 \times 332748131 \equiv 40 \pmod{998244353}$$$.

Input

The input contains several test cases. The first line contains an integer $$$T$$$ indicating the number of test cases. The following describes all test cases. For each test case:

The first line contains an integer $$$n$$$.

Each of the following $$$n$$$ lines contains two integers $$$u$$$ and $$$v$$$, representing an edge between the $$$u$$$-th node and the $$$v$$$-th node.

  • $$$1 \leq T \leq 100$$$
  • $$$3 \leq n \leq 10^5$$$
  • $$$1 \leq u < v \leq n$$$
  • The sum of $$$n$$$ in all test cases does not exceed $$$5 \times 10^5$$$.
  • It is guaranteed that edges for each test case are distinct, which means there are no multiple edges.
Output

For each test case, output a line containing "Case #x: y" (without quotes), where x is the test case number starting from $$$1$$$, and y is the answer to this test case.

ExampleInput
2
5
1 2
1 3
1 4
2 4
2 5
5
1 2
1 3
1 4
1 5
2 5
Output
Case #1: 166374072
Case #2: 332748131

加入题单

上一题 下一题 算法标签: