Surface:
Degree Chung led the meow-haha clan warriors, ready to attack the people.
Hua-Hua clan is a strong people, there are full of wisdom of counselors, with infinite strength of the warrior.
So this war, it will be very difficult.
In order to better attack the group, the degree of the bear decided that the first should be from the internal disintegration of the Lala clan.
The first step is to make the Hua-Hua clan inside can not concentric force, the need for internal clearance.
There are a total of N-hua clan generals, they have a total of M strong relationship, destroy every strong relationship requires a certain price.
Now the degree bears command you need to destroy some strong relationship, so that the internal generals, cannot through these strong relations, connected to a complete connected block, to ensure the smooth progress of the war.
How much should I pay at least?
Input
The subject contains several sets of test data.
The first line of two integers n,m, indicating that there are N generals, m relationships.
Next m line, three integers per line u,v,w. There is a strong relationship between the U generals and the V generals, and it takes a price to destroy the strong relationship W
Data range:
2<=n<=3000
1<=m<=100000
1<=u,v<=n
1<=w<=1000
Output
For each set of test data, the minimum cost of output is required.
Sample Input
2 1
1 2 1
3 3
1 2 5
1 2 4
2 3 3
Sample Output
1
3 General ideas: note. This is a fake algorithm, not considering the whole situation, can only show that the data is too water. The positive solution should be a minimum cut plus FW optimizer, but I won't, so still look at someone else's code to put
If there is a point in itself that is not related to other points, then the price is 0. Then think in a different direction: if you destroy a point, then the weight and the minimum and the number of edges that follow the destruction. If this is the case, it is not concerned with which side it is connected to, only the Benquan value with which it is connected.
Therefore, a one-dimensional array is created, and the subscript represents the point. The value of the array represents the weights and values of the edges to which this point is connected. All that is left is to update the array values according to test instructions, then sweep the array over and ask for a min output. Code:
#include <bits/stdc++.h> using namespace std; const int maxn=3e3+10; int MP[MAXN]; int
Main () {Ios::sync_with_stdio (false);
Freopen ("In.txt", "R", stdin);
int n,m,u,v,w,minl;
while (cin>>n>>m) {minl=1<<30;
Memset (Mp,0,sizeof (MP));
for (int i=0;i<m;++i) {cin>>u>>v>>w;
if (v!=u) {mp[v]+=w;
Mp[u]+=w;
}} for (int i=1;i<=n;++i) minl=min (Minl,mp[i]);
cout<<minl<<endl;
} return 0; }