Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 59176   Accepted: 22723

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

  1. 5 4
  2. 1 2 40
  3. 1 4 20
  4. 2 4 20
  5. 2 3 30
  6. 3 4 10

Sample Output

  1. 50
  2.  
  3. //手打dinic,从我做起!
  1. //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 10000
    #define eps 1e-9
    const int inf=0x7fffffff;   //无限大
    //**************************************************************************************
  2.  
  3. struct edge
    {
        int to,cap,rev;
    };
    vector<edge> g[maxn];
    int level[maxn];
    int iter[maxn];
    void add_edge(int from,int to,int cap)
    {
        g[from].push_back((edge){to,cap,g[to].size()});
        g[to].push_back((edge){from,0,g[from].size()-1});
    }
    void bfs(int s)
    {
        memset(level,-1,sizeof(level));
        queue<int> que;
        level[s]=0;
        que.push(s);
        while(!que.empty())
        {
            int v=que.front();
            que.pop();
            for(int i=0;i<g[v].size();i++)
            {
                edge &e=g[v][i];
                if(e.cap>0&&level[e.to]<0)
                {
                    level[e.to]=level[v]+1;
                    que.push(e.to);
                }
            }
        }
    }
    int dfs(int v,int t,int f)
    {
        if(v==t)return f;
        for(int &i=iter[v];i<g[v].size();i++)
        {
            edge &e=g[v][i];
            if(e.cap>0&&level[v]<level[e.to])
            {
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0)
                {
                    e.cap-=d;
                    g[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }
    int max_flow(int s,int t)
    {
        int flow=0;
        while(1)
        {
            bfs(s);
            if(level[t]<0)return flow;
            memset(iter,0,sizeof(iter));
            int f;
            while((f=dfs(s,t,inf))>0)
                flow+=f;
        }
    }
  4.  
  5. int main()
    {
        int n,m;
        while(cin>>n>>m)
        {
            for(int i=0;i<=m;i++)
                g[i].clear();
            int a,b,c;
            for(int i=0;i<n;i++)
            {
                cin>>a>>b>>c;
                add_edge(a,b,c);
            }
            cout<<max_flow(1,m)<<endl;
        }
    }

poj 1273 Drainage Ditches 网络流最大流基础的更多相关文章

  1. poj 1273 Drainage Ditches (网络流 最大流)

    网络流模板题. ============================================================================================ ...

  2. poj 1273 Drainage Ditches(最大流)

    http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  3. POJ 1273 Drainage Ditches (网络最大流)

    http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  4. poj 1273 Drainage Ditches【最大流入门】

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63924   Accepted: 2467 ...

  5. poj 1273 Drainage Ditches(最大流,E-K算法)

    一.Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clove ...

  6. POJ 1273 Drainage Ditches (网络流Dinic模板)

    Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...

  7. POJ 1273 Drainage Ditches 网络流 FF

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 74480   Accepted: 2895 ...

  8. POJ 1273 Drainage Ditches【最大流】

    题意:给出起点是一个池塘,M条沟渠,给出这M条沟渠的最大流量,再给出终点是一条河流,问从起点通过沟渠最多能够排多少水到河流里面去 看的紫书的最大流,还不是很理解,照着敲了一遍 #include< ...

  9. POJ 1273 Drainage Ditches【最大流模版】

    题意:现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条有向水渠,给出这n条水渠所连接的点和所能流过的最大流量,求从源点到汇点能流过的最大流量 Dinic #include<iost ...

随机推荐

  1. Linux 内核驱动--多点触摸接口【转】

    转自:http://blog.csdn.net/joard_yang/article/details/6225937 译自:linux-2.6.31.14/Documentation/input/mu ...

  2. MVVM模式的模式简介

    MVVM模式简介 MVVM是Model.View.ViewModel的简写,这种模式的引入就是使用ViewModel来降低View和Model的耦合,说是降低View和Model的耦合.也可以说是是降 ...

  3. 『实践』百度地图给多个marker添加右键菜单(删除、更新)

    js: $.getJSON("./GetStationPlaceServlet",function(json){ for(var i=0;i<json.length;i++) ...

  4. mysql中间件 -> Atlas简介&安装

    Atlas简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基础上, ...

  5. java基础66 JavaScript中的事件、localtion对象、screen对象(网页知识)

    1.JavaScript中的事件注册 1.1.事件的注册方式 方式1:直接在html元素上注册 <body onLoad="ready()"></body > ...

  6. AdvStringGrid 复选框、goRowSelect

    var I: Integer; begin do begin AdvStringGrid1.AddCheckBox(, I, True, True); AdvStringGrid1.Cells[,I] ...

  7. jersey中的405错误 method not allowed

  8. MySQL学习笔记:Engine存储引擎

    在使用Mysql建表过程中,有时候会遇到一些奇怪的现象.例如,如何插入数据就是查询不到数据,此时可能是建表的存储引擎设置成为engine=blackhole的原因. 1.engine=innodb 提 ...

  9. How to omit h1 title heading in HTML export

    How to omit h1 title heading in HTML export */--> Introduce how to omit h1 title in the exported ...

  10. HBase混布MapReduce集群学习记录

    一.准备工作 1.1 部署环境 集群规模大概260多台,TSC10机型,机型参数如下: > 1个8核CPU(E5-2620v4) > 64G内存 > HBA,12*4T SATA,1 ...