[Hdu6081] degree of strategic Bear Kingdom

Time Limit: 40000/20000 MS (Java/Others)
Memory Limit: 32768/132768 K (Java/Others)

Problem Description
Degree, King led Meow bear ha Group warriors, ready to attack the group crashed.
crashed the family is a powerful nation, there are full of wisdom counselors have infinite power of the soldiers.
so that a war will be very difficult.
for better offensive crashed family, we should first decide the degree of collapse crashed bear from inside the group.
should be such that the first step is not concentric inner crashed Group Qi, the need for internal gap.
a total aromatic crashed n n Two generals, a total of them m m A strong relationship, destroy every strong relationship requires a certain price.
Degree, now you need to destroy some of the commands bears a strong relationship, such that the interior of the generals, these can not be a strong relationship, even as a full communication block, to ensure smooth war.
should at least ask how much to pay.

Input
The title comprising a plurality of sets of test data.
first line two integers n m n,m , Expressed n n A general. m m A relationship.
Next m m Rows of three integers u , v , w u,v,w . Indicates the presence of a strong relationship between u and v generals generals, to destroy the strong relationship comes at a cost w w

data range:
2 < = n < = 3000 2<=n<=3000
1 < = m < = 100000 1<=m<=100000
1 < = u , v < = n 1<=u,v<=n
1 < = w < = 1000 1<=w<=1000

Output
For each test, the cost required minimum output.

Sample Input

2 1
1 2 1
3 3
1 2 5
1 2 4
2 3 3

Sample Output

1
3

answer:
global minimum cut bare title

Global minimum cut of implementation:
1. selecting a smallest first pair of points in the s-t G is cut, update your answers.
2. The selected s-t merge into a collection.
3. do repeated until only one vertex G.

How to find the minimum in the current state of the cut?
1. (after collection or combined) to pick a starting point.
2. In this starting point, through all points to this (set) by the other adjacent dots (set)
3. root with a large collection heap memory is connected directly to the last added last remaining point and the point that the final expansion union to a set inside the line.

#include<bits/stdc++.h>
#define ll long long
#define pa pair<ll,int>
using namespace std;
const ll INF=1e18;
struct edge{
    int to,w;
};
int n,m;
vector<edge>G[3004];
int f[3004],lk[3004];
int Find(int x){return f[x]==x?x:f[x]=Find(f[x]);}
void Union(int x,int y){
    int p=x;
    while(lk[p])p=lk[p];
    lk[p]=y;
    f[y]=x;
}
ll val[3004];
bool vis[3004];
priority_queue<pa>q;
ll msp(int cnt,int &s,int &t){
    for(int i=1;i<=n;i++){
        vis[i]=0;
        val[i]=0;
    }
    while(!q.empty())q.pop();
    t=1;
    while(--cnt){
        vis[t]=1;
        s=t;
        for(int x=s;x;x=lk[x]){
            for(int i=0;i<G[x].size();i++){
                int to=Find(G[x][i].to),w=G[x][i].w;
                if(!vis[to]){
                    val[to]+=w;
                    q.push({val[to],to});
                }
            }
        }
        t=0;
        while(!t){
            if(q.empty())return 0;
            ll ft=q.top().first;
            int st=q.top().second;
            q.pop();
            if(val[st]==ft){
                t=st;
            }
        }
    }
    return val[t];
}
ll StoerWanger(){
    ll ans=INF;
    int s,t;
    for(int i=n;i>1;i--){
        ans=min(ans,msp(i,s,t));
        if(ans==0)break;
        Union(s,t);
    }
    return ans;
}
int w33ha(){
    for(int i=1;i<=n;i++){
        f[i]=i;
        lk[i]=0;
        G[i].clear();
    }
    for(int i=1;i<=m;i++){
        int u,v,w;scanf("%d%d%d",&u,&v,&w);
        G[u].push_back((edge){v,w});
        G[v].push_back((edge){u,w});
    }
    printf("%lld\n",StoerWanger());
    return 0;
}
int main(){
    while(scanf("%d%d",&n,&m)!=EOF)w33ha();
    return 0;
}

Intelligent Recommendation

Css3 draws Baidu degree bear

The article first appeared on my blog:lanjianguo.github.io/blog/ A few days ago I saw an article about writing Tencent Penguins with css3. Taking advantage of today's time, use css3 to write a small B...

Degree bear and evil big devil

HDU portal This is a fully deformed backpack. We use dp[i][j] to indicate the minimum cost of demons with a blood defense of i. Reprinted at: https://www.cnblogs.com/dfsac/p/7587815.html...

hdu6377 degree of bear to watch the game

link http://acm.hdu.edu.cn/showproblem.php?pid=6377 answer f i j f_{ij} fij​Show i i iArranged to couple with j j jSitting together on a number of programs newly added pair may be transferred to f i ,...

F - Degree, Science queue Bear

topic: Bears are learning degree of double-ended queue, he had a great interest in its flip and merge. NN initially empty when the deque (numbered 11 to NN), you have to bear the support of QQ operati...

More Recommendation

HDU6082 Degree Bear and the Evil Devil

HDU6082 Degree Bear and the Evil Devil Tags: DP, knapsack problem http://www.sakurasake.icoc.me/nd.jsp?id=10 Time Limit: 2000/1000 MS(Java/Others)    Memory Limit: 32768/32768 K (J...

The kingdom strategy of the bear (connected graph - and collected)

The King of the Bears led the warriors of the Haha people and prepared to attack the Lahu people. The is a powerful nation with intelligent strategists and warriors with infinite power. So this war wi...

HDU 6081 Treatment Bear Kingdom Strategy

I started the understanding of the meaning, I looked at other people's understanding, I found a good pit, and there were so many people in the beginning, and the correct rate is also very low, so emba...

Degree Bear's Kingdom Strategy (minimum cut)

Division Kingdom Strategy    Accepts: 30    Submissions: 1605  Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/132768 K (Java/Others) Problem Descrip...

B - Degree Bear Learning Queue HDU - 6375

The Bear is learning the double-ended queue, and he has a lot of interest in flipping and merging. Initially there are N empty double-ended queues (numbered 1 to N), and you want to support the Q oper...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top