zoukankan      html  css  js  c++  java
  • hdu 1532 Drainage Ditches

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 16564    Accepted Submission(s): 7867


    Problem Description
    Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.
    Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
    Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
     
    Input
    The input includes several cases. For each case, the first line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream. Each of the following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which water will flow through the ditch.
     
    Output
    For each case, output a single integer, the maximum rate at which water may emptied from the pond.
     
    Sample Input
    5 4
    1 2 40
    1 4 20
    2 4 20
    2 3 30
    3 4 10
    Sample Output
    50
     
    就是codevs的草地排水 http://www.cnblogs.com/ruojisun/p/6501431.html
    模板最大流问题
    #include <cstring>
    #include <cstdio>
    #include <queue>
    
    using namespace std;
    struct node
    {
        int next,to,flow;
    }edge[200*200+1];
    int deep[200*200],head[200*200+1],ans,s,t,n,m,i,j,cnt=1;
    void add(int u,int v,int l)
    {
        cnt++;
        node * now=&edge[cnt];
        now->next=head[u];
        now->to=v;
        now->flow=l;
        head[u]=cnt;
    }
    bool bfs(int s,int t)
    {
        memset(deep,-1,sizeof(deep));
        deep[s]=0;
        queue<int>q;
        q.push(s);
        while(!q.empty())
        {
            int tp=q.front();
            q.pop();
            for(i=head[tp];i;i=edge[i].next)
            {
                if(deep[edge[i].to]==-1&&edge[i].flow>0)
                {
                    deep[edge[i].to]=deep[tp]+1;
                    if(edge[i].to==t) return 1;
                    else q.push(edge[i].to); 
                }
            }
        }
        return 0;
    }
    int dfs(int now,int t,int came_flow)
    {
        if(now==t||came_flow==0) return came_flow;
        int rest=0,f;
        for(int i=head[now];i;i=edge[i].next)
        {
            int v=edge[i].to;
            if(deep[v]==deep[now]+1&&edge[i].flow>0)
            {
                f=dfs(v,t,min(came_flow,edge[i].flow));
                if(f)
                {
                    rest+=f;
                    came_flow-=f;
                    edge[i].flow-=f;
                    edge[i^1].flow+=f;
                }
                if(came_flow==0) return rest;
            }
        }
        return rest;
    }
    void Dinic(int s,int t)
    {
        while(bfs(s,t))
        ans+=dfs(s,t,1e9);
    }
    int main()
    {
        while(scanf("%d%d",&n,&m)!=EOF)//一定用这个读入,因为这WA了好多次
        {
            int a,b,c;
            s=1,t=m;ans=0;
            memset(head,0,sizeof(head));
            cnt=1;
            while(n--)
            {
                scanf("%d%d%d",&a,&b,&c);
                add(a,b,c);
                add(b,a,0);
            }
            Dinic(s,t);
            printf("%d
    ",ans);
        }
        return 0;
    }
    我们都在命运之湖上荡舟划桨,波浪起伏着而我们无法逃脱孤航。但是假使我们迷失了方向,波浪将指引我们穿越另一天的曙光。
  • 相关阅读:
    ASP.net中页面事件的先后顺序
    我回来了
    ASP.NET中添加引用不能显示
    VS2008中MVC无法打开项目文件,此安装不支持该项目类型
    windows2003 IIS错误
    C#中使用TimeSpan计算两个时间的差值
    javascript做在翻译
    GridView导出EXCEL
    用资源管理器限制大数据量查询
    linux单机配置DG过程记录
  • 原文地址:https://www.cnblogs.com/ruojisun/p/6539545.html
Copyright © 2011-2022 走看看