#abc218e. E - Destruction
E - Destruction
Score : points
问题描述
我们有一个包含 个顶点和 条边的连通无向图。
顶点编号从 到 ,边编号从 到 。边 连接顶点 和 。
高桥将从此图中移除零个或多个边。
当移除边 时,若 ,则会获得奖励 ;若 ,则会产生罚款 。
求在移除边后图形必须保持连通的前提下,高桥可以获得的最大总奖励是多少。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a connected undirected graph with vertices and edges.
The vertices are numbered through , and the edges are numbered through . Edge connects Vertices and .
Takahashi is going to remove zero or more edges from this graph.
When removing Edge , a reward of is given if , and a fine of is incurred if .
Find the maximum total reward that Takahashi can get when the graph must be connected after removing edges.
Constraints
- The given graph is connected.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4 5
1 2 1
1 3 1
1 4 1
3 2 2
4 2 2
Sample Output 1
4
Removing Edges and yields a total reward of . You cannot get any more, so the answer is .
Sample Input 2
3 3
1 2 1
2 3 0
3 1 -1
Sample Output 2
1
There may be edges that give a negative reward when removed.
Sample Input 3
2 3
1 2 -1
1 2 2
1 1 3
Sample Output 3
5
There may be multi-edges and self-loops.
update @ 2024/3/10 09:39:06