#P1268. [ICPC2017 ASIA Daejeon]How Many to Be Happy?

[ICPC2017 ASIA Daejeon]How Many to Be Happy?

题目描述

Let GG 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 ee, how much modification on GG is needed to make ee part of an MST for GG.For an edge ee in GG,there may already exist an MST for GG that includes ee.In that case, we say that ee is happyhappy in GG and we define H(e)H(e) to be 0,However it may happen that there is no MST for GG that includes ee.In such a case,we say that ee is unhappyunhappy in GG.We may remove a few of the edges in GG to make a connectedconnected graph GrqG\\rq. 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 GG,your task is to conpute H(e)H(e)for each edge ee in GG and print the total sum.

输入格式

Your program is to read from standard input. The first line contains two positive integers nn and mm,respectively, representing the numbers of vertices and edges of the input graph, where nle100n\\le 100 and mle500m\\le 500.It is assumed that the graph GG has nn vertices that are indexed from 11 to nn.It is followed by nn lines,each contains 3 positive integers u,vu,v,and ww that represent an edge of the input graph between vertex uu and vertex vv with weight ww. 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 SS,which is the sum of H(e)H(e) where ee ranges over all edges in GG.

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