QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#14649. Obwód elektryczny

统计

Kapitan Bajtazar正在研究Vicugna星球。它在各方面都非常奇特——除了许多有趣的现象(例如存在粉色羊驼这一物种)之外,这颗星球还具有变化的磁场。为了研究磁现象,Bajtazar在星球上选取了$n$个节点,并用$m$根电线将它们连接起来。在这些电线中,由于磁场作用,会产生一定强度的电流,不同电线上的电流强度可能不同。电流遵循物理定律——每根电线上的电流只能沿一个方向流动,并且在每个节点处,流入电流强度之和必须等于流出电流强度之和。

现在Bajtazar想在电线上安装电流表,以测定电流强度。当然,他可以在每根电线上都安装一个电流表,但这会非常耗时、费力,且成本极高。因此Bajtazar正在思考如何把成本降到最低——众所周知,某些电线上的电流强度可以根据其他电线推导出来。

每根电线都有一个在其上安装测量仪器的成本。这个成本可以为正(需要消耗珍贵燃料并使用一个电流表),也可以为负(Bajtazar预计在某些地方能找到美丽的Vicugna星矿物,从而弥补损失)。请找出一种安装电流表的方法(即选择一个合适的电线集合),使得总成本尽可能小,同时仍能确定所有电线上的电流强度。

输入格式

输入第一行包含两个整数$n$和$m$($2 \leq n \leq 200,000$, $1 \leq m \leq 500,000$),分别表示节点数与电线数。接下来$m$行给出电线描述:第$j$行包含三个整数$a_j$, $b_j$, $c_j$($1 \leq a_j, b_j \leq n$, $a_j \neq b_j$, $-10^9 \leq c_j \leq 10^9$),表示第$j$根电线连接节点$a_j$与$b_j$,在其上安装电流表的成本为$c_j$。任意一对节点之间最多由一根电线连接。

输出格式

输出一行一个整数——满足条件的电流表集合的最小总成本。

样例数据

对于输入数据:

4 6
1 2 -1
3 4 6
4 1 4
2 3 3
2 4 2
1 3 3

正确输出为:

4

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.