#P15857. [蓝桥杯第二届国际赛] 资源运输
[蓝桥杯第二届国际赛] 资源运输
Problem Description
Xiao Z has recently become addicted to a game: Galaxy on Fire: Alliances. In this game, you can own many planets. Resources can be mined on each planet, and transporting resources is done by flying a mothership between planets. After exploring, Xiao Z found that, for the planets he currently owns (numbered ), it is best to use exactly routes. Traveling in space has no direction restrictions, so these routes are all bidirectional. Because Xiao Z is not very good at managing things, these optimal routes are not guaranteed to connect all planets. However, smart Xiao Z will never allow more than one route between any two planets, and will never allow a route whose two ends are the same planet.
Since different planets have different mining abilities, each route has its own importance value , representing the value of this route. At the same time, with his rich gaming experience, Xiao Z found that, in order to make his resource transportation optimal, he needs to choose exactly routes from these good routes so that his planets become connected. Of course, there are many ways to choose these routes. Each choice method is a subset of the edges with size . Based on experience, Xiao Z defines the excellence of each choice method as . Smart Xiao Z quickly found the choice method with the maximum excellence, but another problem troubles him: how to compute the average value of the excellence over all these choice methods?
Since Xiao Z really dislikes decimals, he only wants to know this average value modulo .
(Hint: It can be proved that , then you should output an integer such that and .)
Input Format
The first line contains two integers , representing the number of planets and the number of optimal routes.
The next lines each contain three numbers , representing the two planet indices connected by the -th bidirectional route and the importance value of this route.
Output Format
Output one integer , which is the output described in the statement.
3 2
1 3 5
2 1 6
30
7 7
7 6 126
3 7 826
1 2 909
5 6 665
2 3 768
1 4 301
1 3 365
63511277
Hint
Sample 1 Explanation
Obviously, when , there is only one choice method, and the excellence is , so the output is .
Constraints
For the first of the testdata: .
For the first of the testdata: .
There is another of the testdata: .
For all testdata: and , . The importance value of each route satisfies .
Translated by ChatGPT 5