#P6789. 寒妖王
寒妖王
Description
You are given a graph with vertices and edges, guaranteed to have no multiple edges and no self-loops. The -th edge has weight .
Define an edge set as good if and only if the graph formed by taking these edges and the vertices incident to them does not contain two or more different cycles within the same connected component (two cycles are considered different if their edge sets are not completely identical). Also define the weight of an edge set as the sum of the weights of all edges in the set.
Now, each edge disappears with probability . After the disappearance process ends, find the expected value of the weight of the maximum-weight good edge set in the remaining graph.
Output this expected value modulo the large prime .
It can be shown that this expected value is a rational number. Its value modulo is obtained by writing it in lowest terms (where and are coprime), and then computing .
Input Format
The first line contains two positive integers , representing the number of vertices and edges of the graph.
The next lines each contain three integers , describing the two endpoints of the -th edge and its weight.
Output Format
Output one positive integer on one line, representing the answer.
4 6
2 3 294405877
3 4 340909188
1 2 7718822
2 4 340754548
1 4 209906514
1 3 810986947
121593921
Hint
Constraints
- For the first of the testdata, , ;
- For the first of the testdata, , ;
- For another of the testdata, all edge weights are equal;
- For all testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号