Minimal Cut

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

Today Rikka got an undirected graph GG with nn vertices and mm edges. The vertices are numbered by integers from 11 to nn. The ii-th edge connects vertices u_iu\_i and v_iv\_i, and its weight is w_iw\_i.

Rikka likes Hamiltonian graphs: the ones that have a Hamiltonian cycle. Therefore, Rikka constructs a graph based on GG that is surely Hamiltonian. She does so by inserting nn extra edges: the ii-th edge connects vertices ii and (imodn+1)(i \bmod n + 1), and its weight is 10910^9.

Let c(i,j)c (i, j) be the value of the minimal cut between the ii-th and the jj-th vertices. Rikka wants you to calculate _i=1n_j=i+1nc(i,j).\sum\limits\_{i = 1}^n \sum\limits\_{j = i + 1}^{n} c (i, j)\text{.}

Given a graph G_0=V,EG\_0 = \langle V, E \rangle, a set of edges CEC \subseteq E is a cut between vertices ii and jj if and only if in graph G_1=V,ECG\_1 = \langle V, E \setminus C \rangle, vertices ii and jj are not (indirectly or directly) connected. The minimal cut between ii and jj is the cut with the minimal sum of edge weights. The value c(i,j)c (i, j) of the minimal cut is this minimal sum itself.

입력

The first line contains two integers nn and mm (3n20,0003 \leq n \leq 20\\,000, 0m20,0000 \leq m \leq 20\\,000).

Then mm lines follow. Each of them contains three integers u_iu\_i, v_iv\_i, and w_iw\_i (1u_i,v_in1 \leq u\_i, v\_i \leq n, u_iv_iu\_i \neq v\_i and 1w_i10,0001 \leq w\_i \leq 10\\,000).

Note that the graph has no self-loops, but may contain multiple edges.

출력

Output a single line with a single integer, the answer modulo 998,244,353998\\,244\\,353.