QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 1024 MB 満点: 100

#12030. Minimum Cut

統計

Kaguya wants to design a graph theory problem.

Given an undirected graph $G$ with $n$ vertices and $m$ edges without self-loops, where the $i$-th edge connects $(u_i, v_i)$ with weight $w_i$ ($1 \leq w_i \leq 10^4$).

Based on $G$, Kaguya constructs a new graph $G'$, where $G'$ is formed by adding $n$ edges to $G$. The $i$-th added edge connects $i$ and $i \text{ mod } n + 1$ with a weight of $10^9$.

Let $f(u, v)$ be the size of the minimum cut between $u$ and $v$ in $G'$. Kaguya wants you to calculate $\sum_{i=1}^n \sum_{j=i+1}^{n} f(i, j)$.

An edge set $E$ is a cut between $u$ and $v$ if and only if $u$ cannot reach $v$ after removing the edges in $E$. The size of a cut is defined as the sum of the weights of all edges in the cut, and the minimum cut between $u$ and $v$ is the cut with the minimum size among all such cuts.

Input

The first line contains two integers $n, m$ ($1 \leq n \leq 7000, 1 \leq m \leq 10^5$).

The next $m$ lines each contain three integers $u_i, v_i, w_i$ ($1 \leq u_i \neq v_i \leq n, 1 \leq w_i \leq 10^4$), describing an edge in $G$.

Output

Output a single integer representing the answer. Since the answer may be very large, output it modulo $998244353$.

Subtasks

Subtask 1 (19 points): $n \leq 80, m \leq 200$.

Subtask 2 (23 points): $n \leq 300, m \leq 1000$.

Subtask 3 (26 points): $n \leq 1000$.

Subtask 4 (32 points): No additional constraints.

Examples

Input 1

4 2
1 3 2
2 4 2

Output 1

21067776

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.