QOJ.ac

QOJ

Time Limit: 0.5 s Memory Limit: 512 MB Total points: 100

#13111. 需要多少才能快乐?

Statistics

设 $G$ 是一个连通简单无向图,每条边都有一个关联的权重。让我们考虑经典的 MST(最小生成树)问题。今天,我们将研究对于每条边 $e$,需要对 $G$ 进行多少修改才能使 $e$ 成为 $G$ 的 MST 的一部分。对于 $G$ 中的一条边 $e$,如果 $G$ 中已经存在包含 $e$ 的 MST,那么我们称 $e$ 在 $G$ 中是“快乐的”(happy),并定义 $H(e) = 0$。然而,可能存在 $G$ 中没有任何 MST 包含 $e$ 的情况。在这种情况下,我们称 $e$ 在 $G$ 中是“不快乐的”(unhappy)。我们可以从 $G$ 中移除一些边,得到一个连通子图 $G'$,使得 $e$ 在 $G'$ 中是快乐的。我们定义 $H(e)$ 为使得 $e$ 在结果图 $G'$ 中快乐所需从 $G$ 中移除的最小边数。

图 E.1. 一个包含 3 个节点的完全图。

考虑图 E.1。该图有 3 个节点和 3 条连接节点的边。可以很容易地看出,该图的 MST 包含权重为 1 和 2 的 2 条边,因此这两条边在图中是快乐的。如何使权重为 3 的边变得快乐呢?显然,我们可以移除两条快乐边中的任意一条来实现这一点。

给定一个连通简单无向图 $G$,你的任务是计算 $G$ 中每条边 $e$ 的 $H(e)$,并输出总和。

输入格式

程序从标准输入读取数据。第一行包含两个正整数 $n$ 和 $m$,分别表示输入图的顶点数和边数,其中 $n \le 100$ 且 $m \le 500$。假设图 $G$ 有 $n$ 个顶点,编号从 1 到 $n$。接下来有 $m$ 行,每行包含 3 个正整数 $u$、$v$ 和 $w$,表示顶点 $u$ 和顶点 $v$ 之间存在一条权重为 $w$ 的边。权重为 1 到 500 之间的整数(包含 1 和 500)。

输出格式

程序将结果写入标准输出。唯一的一行应包含一个整数 $S$,即 $H(e)$ 对 $G$ 中所有边求和的结果。

样例

输入 1

3 3
1 2 1
3 1 2
3 2 3

输出 1

1

输入 2

7 9
1 2 8
1 3 3
2 3 6
4 2 7
4 5 1
5 6 9
6 7 3
7 4 2
4 6 2

输出 2

3

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.