atcoder#ABC218E. [ABC218E] Destruction
[ABC218E] Destruction
Score : points
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.
4 5
1 2 1
1 3 1
1 4 1
3 2 2
4 2 2
4
Removing Edges and yields a total reward of . You cannot get any more, so the answer is .
3 3
1 2 1
2 3 0
3 1 -1
1
There may be edges that give a negative reward when removed.
2 3
1 2 -1
1 2 2
1 1 3
5
There may be multi-edges and self-loops.