#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 NN dealers to distribute “One-Eyed Little Buddy”. The NN dealers are numbered 1,2,,N1,2,\cdots,N in order.

Among the NN dealers, there are MM trading relationships in total, numbered 1,2,,M1,2,\cdots,M in order. The ii-th trading relationship connects dealers uiu_i and viv_i. For the ii-th trading relationship, when one side learns the production information of “One-Eyed Little Buddy”, it will tell the other side with probability piqi\dfrac{p_i}{q_i}. 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 a1,a2,,ak(k>2)a_1,a_2,\cdots,a_k(k>2) form a business group if and only if there exist kk distinct trading relationships such that the ww-th relationship connects dealers awa_w and awmodk+1a_{w \bmod k+1}. Formally, a business group corresponds to kk 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 QQ independent tests in total. In the ii-th test, Tartaglia tells the production information of “One-Eyed Little Buddy” to dealer SiS_i. 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 pq\dfrac{p}{q}. You need to output the value of pq1(mod998 244 353)p\cdot q^{-1}\pmod {998\ 244\ 353}.

Input Format

The input has M+Q+1M+Q+1 lines.

The first line contains three positive integers N,M,QN,M,Q, representing the number of dealers, the number of trading relationships, and the number of tests.

The next MM lines each contain four positive integers ui,vi,pi,qiu_i,v_i,p_i,q_i, representing the dealers connected by the ii-th trading relationship and the probability of telling.

The next QQ lines each contain one integer SiS_i, representing the dealer who is told in the ii-th test.

Output Format

Output QQ lines. For each query, output one integer per line, representing the expected value modulo 998 244 353998\ 244\ 353.

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 1616 possible connectivity cases of the graph. From top to bottom and left to right, they are numbered 1161\sim 16 in order. For the query at node 11, we compute, for each of the 1616 cases, the number of nodes reachable from node 11 and the probability of that case:

Graph ID Number of nodes Probability Expectation
11 44 160\frac{1}{60} 115\frac{1}{15}
22 11 160\frac{1}{60}
33 44 130\frac{1}{30} 215\frac{2}{15}
44 115\frac{1}{15} 415\frac{4}{15}
55 160\frac{1}{60} 115\frac{1}{15}
66 11 130\frac{1}{30}
77 115\frac{1}{15}
88 160\frac{1}{60}
99 33 215\frac{2}{15} 25\frac{2}{5}
1010 22 130\frac{1}{30} 115\frac{1}{15}
1111 33 115\frac{1}{15} 15\frac{1}{5}
1212 11 215\frac{2}{15}
1313 130\frac{1}{30}
1414 115\frac{1}{15}
1515 22 215\frac{2}{15} 415\frac{4}{15}
1616 11 215\frac{2}{15}

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 1N,M,Q3×1051 \leq N,M,Q \leq 3 \times 10^5, 1ui,viN1 \le u_i,v_i \le N, uiviu_i\neq v_i, 1pi,qi<998 244 3531 \le p_i,q_i < 998\ 244\ 353, 1SiN1 \le S_i \le N.

Test point ID N,M,QN,M,Q\le Special property
121\sim 2 1717 None
343\sim 4 2×1032\times 10^3 A
575\sim 7 B
898\sim 9 None
101310\sim 13 3×1053\times 10^5 A
141914\sim 19 B
202520\sim 25 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