QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#2889. Dense Subgraph

統計

One day, the magician Little L saw a directed complete graph. The length of every edge in the graph is 1, and all edges are initially white. Now, Little L is going to cast a spell on this graph. Each directed edge in the graph has a certain probability of turning black. Little L considers a graph to be "dense" if and only if, considering only the black edges, the shortest path length from node 1 to all other nodes does not exceed $k$ (specifically, if two nodes are not connected, the shortest path length between them is considered $+\infty$). Little L wants to know the probability that this directed complete graph is "dense". Please output the result of this probability modulo $998,244,353$.

Input

Read data from standard input. The first line contains two positive integers $n (2 \le n \le 12)$ and $k (1 \le k \le n - 1)$. The next $n \times (n - 1)$ lines each contain four positive integers $x, y, p, q$, representing that the probability of the directed edge from node $x$ to node $y$ turning black is $\frac{p}{q}$. It is guaranteed that $1 \le x \le n, 1 \le y \le n, x \neq y, 0 \le p \le q < 998,244,353, q > 0$, and each valid pair $(x, y)$ appears exactly once.

Output

Output to standard output. A single integer representing the answer.

Examples

Input 1

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

Output 1

166374059

Note

The directed complete graph is "dense" if and only if the directed edge from node 1 to node 2 and the directed edge from node 1 to node 3 both turn black. The probability of this occurring is $\frac{1}{2} \times \frac{1}{3} = \frac{1}{6}$. $\frac{1}{6} \pmod{998,244,353} = 166,374,059$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.