#P7142. [THUPC 2021 初赛] 密集子图
[THUPC 2021 初赛] 密集子图
Description
One day, the wizard Xiao L saw a complete directed graph.
All edges in the graph have length , and all edges are white.
Now Xiao L wants to cast magic on this graph. Each directed edge independently has a certain probability of turning black.
Xiao L considers a graph to be "dense" if and only if, when traveling using only black edges, the shortest path length from node to every other node is at most (in particular, if two nodes are not connected, the shortest path length between them is considered ).
Xiao L wants to know: what is the probability that this complete directed graph is "dense"? Please output this probability modulo .
Input Format
The first line contains two positive integers ( and ().
In the next lines, each line contains four positive integers , meaning that the probability that the directed edge from node to node turns black is . It is guaranteed that , , , , , and each valid appears exactly once.
Output Format
Output one integer in a single line, representing the answer.
3 1
1 2 1 2
2 1 1 2
1 3 1 3
3 1 2 3
2 3 3 4
3 2 2 5
166374059
Hint
[Sample Explanation #1]
This complete directed graph is "dense" if and only if both the directed edge from node to node and the directed edge from node to node turn black. The probability of this happening is , and $\frac{1}{6} \bmod 998,244,353 = 6^{998,244,351} \bmod 998,244,353 = 166,374,059$.
[Source]
From the preliminary round of the 2021 Tsinghua University Student Programming Contest and Intercollegiate Invitational (THUPC2021).
Solutions and other resources can be found at https://github.com/THUSAAC/THUPC2021-pre.
Translated by ChatGPT 5
京公网安备 11011102002149号