zoukankan      html  css  js  c++  java
  • HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】

    Problem Description

    Consider a network G=(V,E) with source s and sink t . An s-t cut is a partition of nodes set V into two parts such that s and t belong to different parts. The cut set is the subset of E with all edges connecting nodes in different parts. A minimum cut is the one whose cut set has the minimum summation of capacities. The size of a cut is the number of edges in the cut set. Please calculate the smallest size of all minimum cuts.
     
    Input
    The input contains several test cases and the first line is the total number of cases T (1T300) .
    Each case describes a network G , and the first line contains two integers n (2n200) and m (0m1000) indicating the sizes of nodes and edges. All nodes in the network are labelled from 1 to n .
    The second line contains two different integers s and t (1s,tn) corresponding to the source and sink.
    Each of the next m lines contains three integers u,v and w (1w255) describing a directed edge from node u to v with capacity w .
     

    Output

    For each test case, output the smallest size of all minimum cuts in a line.
     

    Sample Input

    2 4 5 1 4 1 2 3 1 3 1 2 3 1 2 4 1 3 4 2 4 5 1 4 1 2 3 1 3 1 2 3 1 2 4 1 3 4 3
     Sample Output
    2 3
     
    Source
     
    【题意】: 求最小割中最少的边数。
    【代码】:在建图时,每个边权乘以一个大的数E,然后加1,求出最大流后对E取模,就可以得到边数。
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<vector>
    #include<stack>
    #include<bitset>
    #include<cstdlib>
    #include<sstream>
    #include<cctype>
    #include<cmath>
    #include<set>
    #include<list>
    #include<deque>
    #include<map>
    #include<queue>
    using namespace std;
    
    typedef long long ll;
    const double PI=acos(-1.0);
    const double eps=1e-6;
    const int INF=0x3f3f3f3f;
    const int maxn=9876;
    
    int T;
    int n,m,s,t;
    int ans,flag,tot;
    
    int head[maxn],path[maxn],vis[maxn];
    
    struct Edge
    {
        int from,to;
        int cap;
        int next;
    }e[maxn];
    
    void init()
    {
        tot=0;
        memset(head,-1,sizeof(head));
        memset(vis,0,sizeof(vis));
        memset(path,0,sizeof(path));
    }
    
    void add_edge(int u,int v,int w)
    {
        e[tot].from=u;
        e[tot].to=v;
        e[tot].cap=w;
        e[tot].next=head[u];
        head[u]=tot++;
    }
    
    int bfs()
    {
        queue<int>q;
        q.push(s);
        vis[s]=1;
        path[s]=-1;
        while(!q.empty())
        {
            int u=q.front();
            q.pop();
            for(int i=head[u];i!=-1;i=e[i].next)
            {
                int v=e[i].to;
                if(e[i].cap>0&&!vis[v])
                {
                    path[v]=i;
                    vis[v]=1;
                    if(v==t)
                        return 1;
                    q.push(v);
                }
            }
        }
        return 0;
    }
    
    int EK()
    {
        int maxFlow=0;
        int flow,i;
        while(bfs())
        {
            memset(vis,0,sizeof(vis));
            i=path[t];
            flow=INF;
            while(i!=-1)
            {
                flow=min(flow,e[i].cap);
                i=path[e[i].from];
            }
            i=path[t];
            while(i!=-1)
            {
                e[i].cap-=flow;
                e[i^1].cap+=flow;
                i=path[e[i].from];
            }
            maxFlow+=flow;
        }
        return maxFlow;
    }
    
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&m);
            init();
            scanf("%d%d",&s,&t);
            for(int i=0;i<m;i++)
            {
                int a,b,c;
                scanf("%d%d%d",&a,&b,&c);
                add_edge(a,b,c*1000+1);
                add_edge(b,a,0);
            }
            printf("%d
    ",EK()%1000);
        }
        return 0;
    }
    E  K
  • 相关阅读:
    【转】css解决兼容的问题
    【转】.NET完美实现伪静态页面,URLRewriter.dll下载
    【技术贴】网站首页浏览量统计代码,适合.NET||网页浏览量计数器代码
    js过滤空格回车
    男人帮所有手机铃声下载|左永邦手机铃声下载,顾小白手机铃声下载,米琪手机铃声下载,艾米手机铃声下载
    孙红雷男人帮全集迅雷下载
    【技术帖】Mysql The 'InnoDB' feature is disabled; you n
    周杰伦2011所有歌曲完整版无删节全正版打包免费下载 http://115.com/file/bhr
    红警95 3D重置版 下载地址|3D95红警下载地址
    周杰伦2011所有歌曲完整版无删节全正版打包免费下载 http://115.com/file/bhr
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7538956.html
Copyright © 2011-2022 走看看