201,700-degree star Qualifying 1002-degree bear's kingdom strategy "figure + greedy"

Source: Internet
Author: User
Tags min
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; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.