#P1268. [ICPC2017 ASIA Daejeon]How Many to Be Happy?
[ICPC2017 ASIA Daejeon]How Many to Be Happy?
题目描述
Let be a connected simple undirected graph where each edge hsa an associated weight. Let's consider Let’s consider the popular MST (Minimum Spanning Tree) problem. Today, we will see, for each edge , how much modification on is needed to make part of an MST for .For an edge in ,there may already exist an MST for that includes .In that case, we say that is in and we define to be 0,However it may happen that there is no MST for that includes .In such a case,we say that is in .We may remove a few of the edges in to make a graph . Consider the graph in Figure E.1. There are 3 nodes and 3 edges connecting the nodes. One can easily see that the MST for this graph includes the 2 edges with weights 1 and 2, so the 2 edges are happy in the graph. How to make the edge with weight 3 happy? It is obvious that one can remove any one of the two happy edges to achieve that.
Given a connected simple undirected graph ,your task is to conpute for each edge in and print the total sum.
输入格式
Your program is to read from standard input. The first line contains two positive integers and ,respectively, representing the numbers of vertices and edges of the input graph, where and .It is assumed that the graph has vertices that are indexed from to .It is followed by lines,each contains 3 positive integers ,and that represent an edge of the input graph between vertex and vertex with weight . The weights are given as integers between 1 and 500, inclusive.
输出格式
Your program is to write to standard output. The only line should contain an integer ,which is the sum of where ranges over all edges in .
The following shows sample input and output for two test cases.
样例
3 3
1 2 1
3 1 2
3 2 3
1
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
3