#P15857. [蓝桥杯第二届国际赛] 资源运输

    ID: 17927 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>2018矩阵树定理蓝桥杯国赛

[蓝桥杯第二届国际赛] 资源运输

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 nn planets he currently owns (numbered 1∼n1 \sim n), it is best to use exactly mm routes. Traveling in space has no direction restrictions, so these mm routes are all bidirectional. Because Xiao Z is not very good at managing things, these optimal routes are not guaranteed to connect all nn 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 WiW_i, 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 n−1n - 1 routes from these mm good routes so that his nn planets become connected. Of course, there are many ways to choose these n−1n - 1 routes. Each choice method PP is a subset of the mm edges with size n−1n - 1. Based on experience, Xiao Z defines the excellence of each choice method as VP=∏Wp(p∈P)V_P = \prod W_p (p \in P). 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 AnsAns modulo 998244353998244353.

(Hint: It can be proved that Ans=p/q(p,q∈N)Ans = p/q (p, q \in \mathbb{N}), then you should output an integer ss such that 0≤s<9982443530 \le s < 998244353 and s⋅q≡p(mod998244353)s \cdot q \equiv p \pmod{998244353}.)

Input Format

The first line contains two integers n,mn, m, representing the number of planets and the number of optimal routes.

The next mm lines each contain three numbers Ui,Vi,WiU_i, V_i, W_i, representing the two planet indices connected by the ii-th bidirectional route and the importance value of this route.

Output Format

Output one integer ss, 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 m=n−1m = n - 1, there is only one choice method, and the excellence is 5×6=305 \times 6 = 30, so the output is 3030.

Constraints

For the first 15%15\% of the testdata: n,m≤15n, m \le 15.

For the first 40%40\% of the testdata: n,m≤50n, m \le 50.

There is another 10%10\% of the testdata: m≤nm \le n.

For all testdata: n≤300n \le 300 and n−1≤m≤1000n - 1 \le m \le 1000, n≥2n \ge 2. The importance value of each route satisfies 0≤c<9982443530 \le c < 998244353.

Translated by ChatGPT 5