Can They Go to Galar?
题号:NC52010
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Pokemons are planning their travel to the new region Galar. However, it is difficult to allow all of them to go there due to limited funds.

There are n pokemons all over the world, numbered from 1 to n. We decide who can go to Galar according to the following rules.

We start with a cactus (i.e. a connected graph in which every edge belongs to at most one simple cycle) having n vertices and m bidirectional edges, where the i-th vertex represents the pokemon i and each edge has a probability to go through.

Pokemons go to Galar in rounds. In the first round, only the pokemon 1 is allowed to go to Galar. In the i-th round (), if pokemon u has got the permission to Galar in the (i - 1)-th round, pokemon v hasn't got the permission yet, and there is an edge between pokemon u and pokemon v with probability w to go through, then pokemon v will have a probability w to go to Galar in this round. If there is no pokemon that can get permission, the further rounds will be skipped. You can see the note after the sample for better understanding of this procedure.

Please calculate the expected population of pokemons that can travel to Galar. In order to avoid precision issues, output the expected value modulo 998244353. Formally, let the answer be , you need to output the minimum non-negative integer r satisfying that . For example, .

输入描述:

There are multiple test cases. The first line contains an integer T (), indicating the number of test cases. Test cases are given in the following.

For each test case, the first line contains two integers n, m (, ), representing the number of vertices and the number of edges in the cactus respectively.

Each of the next m lines contains four integers u, v, a, b (, , ), representing an edge between the u-th vertex and the v-th one with probability to go through. We ensure that the given graph is a cactus with no self-loops or multiple edges.

输出描述:

For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1, and y denotes the answer to this test case modulo 998244353.
示例1

输入

复制
2
2 1
1 2 1 2
3 3
1 2 1 2
2 3 1 2
3 1 1 2

输出

复制
Case #1: 499122178
Case #2: 748683267

说明

In the second example case, there are six possible cases in total as following.

1. \lbrace 1 \rbrace \to \emptyset with probability \frac{1}{4}.
2. \lbrace 1 \rbrace \to \lbrace 2 \rbrace \to \emptyset with probablity \frac{1}{8}.
3. \lbrace 1 \rbrace \to \lbrace 2 \rbrace \to \lbrace 3 \rbrace \to \emptyset with probablity \frac{1}{8}.
4. \lbrace 1 \rbrace \to \lbrace 3 \rbrace \to \emptyset with probablity \frac{1}{8}.
5. \lbrace 1 \rbrace \to \lbrace 3 \rbrace \to \lbrace 2 \rbrace \to \emptyset with probablity \frac{1}{8}.
6. \lbrace 1 \rbrace \to \lbrace 2, 3 \rbrace \to \emptyset with probablity \frac{1}{4}.

Hence, the answer is 1 \times \frac{1}{4} + 2 \times \frac{1}{8} + 3 \times \frac{1}{8} + 2 \times \frac{1}{8} + 3 \times \frac{1}{8} + 3 \times \frac{1}{4} = \frac{9}{4}.