#P10203. [湖北省选模拟 2024] 玩具销售员 / tartaglia
[湖北省选模拟 2024] 玩具销售员 / tartaglia
Background
Childhood dreams are the easiest things to break. Even if you leave them alone, one day they will break by themselves. So there must be someone to protect them.
Problem Description
“One-Eyed Little Buddy” is Toke’s favorite toy. As the best toy salesman in Liyue, Tartaglia recruited dealers to distribute “One-Eyed Little Buddy”. The dealers are numbered in order.
Among the dealers, there are trading relationships in total, numbered in order. The -th trading relationship connects dealers and . For the -th trading relationship, when one side learns the production information of “One-Eyed Little Buddy”, it will tell the other side with probability . Formally, the dealers and their trading relationships form an undirected graph. The testdata guarantees that this undirected graph is connected, has no self-loops, and has no multiple edges.
Some dealers form a business group if and only if there exist distinct trading relationships such that the -th relationship connects dealers and . Formally, a business group corresponds to dealers and a simple cycle in their trading-relationship graph. A dealer belongs to at most one business group.
Now, Tartaglia wants to test these dealers. He performs independent tests in total. In the -th test, Tartaglia tells the production information of “One-Eyed Little Buddy” to dealer . Under expectation, how many dealers will learn this information in total?
It can be proven that the expectation can always be written in the form . You need to output the value of .
Input Format
The input has lines.
The first line contains three positive integers , representing the number of dealers, the number of trading relationships, and the number of tests.
The next lines each contain four positive integers , representing the dealers connected by the -th trading relationship and the probability of telling.
The next lines each contain one integer , representing the dealer who is told in the -th test.
Output Format
Output lines. For each query, output one integer per line, representing the expected value modulo .
4 4 1
1 2 1 2
3 2 1 3
3 4 1 5
2 4 1 2
1
565671802
9 9 5
9 3 3 5
9 1 1 2
9 2 1 1
4 7 4 5
2 4 2 3
6 8 1 4
5 6 1 3
3 5 2 5
8 3 3 5
1
3
4
7
5
35936800
46584741
380663851
584039500
757135070
见选手目录下的 tartaglia/tartaglia3.in 与 tartaglia/tartaglia3.ans。
该样例满足测试点 1 ∼ 2 的限制。
见选手目录下的 tartaglia/tartaglia4.in 与 tartaglia/tartaglia4.ans。
该样例满足测试点 10 ∼ 13 的限制。
见选手目录下的 tartaglia/tartaglia5.in 与 tartaglia/tartaglia5.ans。
该样例满足测试点 14 ∼ 19 的限制。
见选手目录下的 tartaglia/tartaglia6.in 与 tartaglia/tartaglia6.ans。
Hint
Sample Explanation 1

The figures above show all possible connectivity cases of the graph. From top to bottom and left to right, they are numbered in order. For the query at node , we compute, for each of the cases, the number of nodes reachable from node and the probability of that case:
| Graph ID | Number of nodes | Probability | Expectation |
|---|---|---|---|
Summing up, we get $E=\sum E_i=\frac{59}{30}\equiv 565\ 671\ 802\pmod{998\ 244\ 353}$.
Subtasks
For all testdata, it is guaranteed that , , , , .
| Test point ID | Special property | |
|---|---|---|
| None | ||
| A | ||
| B | ||
| None | ||
| A | ||
| B | ||
| None |
Special property A: No groups exist.
Special property B: There is one and only one group.
Notes
In this problem, you may need to use a larger stack space. In the final test, the stack space memory limit available to the program is the same as the problem’s memory limit.
If you are using Linux, you can use the command ulimit -s unlimited to remove the system stack space limit. If you are using Windows, you can add -Wl,--stack=1024000000 after the compile command to change the system stack space limit to about 1024 MiB.
Translated by ChatGPT 5