All Pair Maximum Flow

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

문제

You are given an undirected graph. You want to compute the maximum flow from each vertex to every other vertex.

The graph is special. You can regard it as a convex polygon with nn points (vertices) and some line segments (edges) connecting them. The vertices are labeled from 11 to nn in the clockwise order. The line segments can only intersect each other at the vertices.

Each edge has a capacity constraint. 

Denote the maximum flow from ss to tt by f(s,t)f(s,t). Output (_s=1n_t=s+1nf(s,t))mod998244353\left(\sum\_{s=1}^n \sum\_{t=s+1}^n f(s,t) \right) \bmod 998244353.

입력

The first line contains two integers nn and mm, representing the number of vertices and edges (3n200000,nm4000003\le n\le 200000, n\le m\le 400000).

Each of the next mm lines contains three integers u,v,wu, v, w denoting the two endpoints of an edge and its capacity (1u,vn,0w10000000001\le u, v\le n, 0\le w\le 1000000000).

It is guaranteed there are no multiple edges and self-loops.

It is guaranteed that there is an edge between vertex ii and vertex (imodn)+1(i\bmod n)+1 for all i=1,2,,ni=1,2,\ldots, n.

출력

Output the answer in one line.