Under construction

Still being built. Things may change

Minimal Cut

Time limit3sMemory limit1024 MB

Summary
Given a weighted undirected graph plus a cycle of 10^9-weight edges through all vertices, sum the minimum cut values over all vertex pairs modulo 998244353.
Level

Hard9 of 10

Topics
Graph, Divide and conquer
Solved
No attempts yet

Problem

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 uiu_i and viv_i, and its weight is wiw_i.

Rikka likes Hamiltonian graphs, that is, graphs that have a Hamiltonian cycle. So Rikka builds a graph from GG that is always Hamiltonian. She does this by adding nn extra edges. The ii-th extra edge connects vertices ii and (i mod n+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 vertices ii and jj. A set of edges C⊆EC \subseteq E is a cut between ii and jj if, in the graph G1=⟨V,E∖C⟩G_1 = \langle V, E \setminus C \rangle, vertices ii and jj are not connected, directly or indirectly. The minimal cut is the cut with the smallest total edge weight, and c(i,j)c(i, j) is that total.

Rikka asks you to compute the following sum. ∑i=1n∑j=i+1nc(i,j)\sum_{i=1}^{n} \sum_{j=i+1}^{n} c(i, j)

Input

The first line contains two integers nn and mm (3≤n≤200003 \leq n \leq 20000, 0≤m≤200000 \leq m \leq 20000).

Each of the next mm lines contains three integers uiu_i, viv_i, and wiw_i (1≤ui,vi≤n1 \leq u_i, v_i \leq n, ui≠viu_i \neq v_i, 1≤wi≤100001 \leq w_i \leq 10000).

The graph has no self-loops, but it may contain multiple edges.

Output

Print a single line containing the answer modulo 998244353998244353.

Examples1

  1. Example 1

    Input
    4 2
    1 3 2
    2 4 2
    
    Expected output
    21067776