9129: Broken Dream

内存限制:256 MB 时间限制:8 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

    People comfort and hug each other along the way, where they struggle desperately to chase their broken and dying dream, which has long been an old friend of theirs, since the good old days.
    So does Akura. His dream is also broken now, and he wanted to make it reunited so that he can finally achieve it. From his perspective, his dream has already broken into several islands in the ocean, and there are bridges between some pair of islands, and every bridge has its own length. Akura's task is to find some bridges that connect all these islands while minimizing the total length of the chosen bridges. However, not every bridge is available, there are possibilities that some bridges are broken. So he wants you to help him find the expectation of the total length of bridges you have to choose so that all islands are connected. If in some situations there were no such selection to do so, you don't need to choose any bridges.
    Formally speaking, there are n islands and m bridges. The i−th bridge connects the ui−th and vi−th island and has the length of wi and the possibility of pi that the bridge is available. Your task is to find the expectation of the total length of the bridges in the MST(minimum spanning tree) modulo 998244353. Note that if in some situations there is no MST in the graph, we consider the total length of bridges in MST to be 0.

输入格式

    The input consists of multiple test cases. The first line contains a single integer T(1 ≤ T ≤ 7) — the number of test cases.
    The first line of each test case contains 2 integers n, m(n ≤ 15, m ≤ 50).
    The following are m lines.
    The i−th line contains 4 integers ui, vi, wi, pi (1 ≤ ui, vi ≤ n, 0 ≤ wi < 998244353, 2 ≤ pi < 998244353), where pi is the possibility modulo 998244353.

输出格式

    An integer, the expectation modulo 998244353.

输入样例 复制

1
3 3
1 2 1 499122177
2 3 2 332748118
3 1 1 499122177

输出样例 复制

1

数据范围与提示

    In the example, p1 = p3 =1/2, p2 =1/3.

分类标签