Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 67387   Accepted: 26035

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

_________________________________________________________________

这好像是道网络流模板题

但为何我做得一点模板样都没有

/*POJ1273 Drainage Ditches*/
//网络流模板题
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
const int INF=1000000;
struct Ed{
int f,t;
int cap,flow;
Ed(int u,int v,int c,int f):f(u),t(v),cap(c),flow(f){}
};
int s,n,m;//起点,结点数,终点
vector<Ed> e;//边
vector<int> G[2000];//邻接表,存储边序号
int a[600];//残量
int p[600];//保存线路用以回溯
//
void clear1(int n){//初始化
for(int i=0;i<=n;i++) G[i].clear();
e.clear();
}
void add_edge(int from,int to,int cap){//添加边,正反向边相邻存储
e.push_back(Ed(from,to,cap,0));
e.push_back(Ed(to,from,0,0));
int si=e.size();
G[from].push_back(si-2);
G[to].push_back(si-1);//相邻两条边分别加入邻接表
return;
}
int fl(){
int res=0,i;
for(;;){//BFS
memset(a,0,sizeof(a));
queue<int>q;
q.push(s);
a[s]=INF;
while(!q.empty()){
int x=q.front();//本轮出发点
q.pop();
for(i=0;i<G[x].size();i++){
Ed& edge=e[G[x][i]];
if(!a[edge.t] && edge.cap>edge.flow){//之前未到达,且结点有剩余流量
a[edge.t]=min(a[x],edge.cap-edge.flow);
p[edge.t]=G[x][i];
q.push(edge.t);
} <pre name="code" class="cpp"> if(a[m])break;//找到增广路,退出

}if(!a[m])break;//无增广路,结束 for(int u=m;u!=s;u=e[p[u]].f){e[p[u]].flow+=a[m];// e[p[u]^1].flow-=a[m];}res+=a[m];}return res;}int main(){s=1;while(scanf("%d%d",&n,&m)!=EOF){clear1(n);int i,j,u,v,c;for(i=1;i<=n;i++){scanf("%d%d%d",&u,&v,&c);add_edge(u,v,c);}printf("%d\n",fl());}return
0;}

												

POJ 1273 Drainage Ditches的更多相关文章

  1. poj 1273 Drainage Ditches(最大流)

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

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

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

  3. poj 1273 Drainage Ditches 最大流入门题

    题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...

  4. POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]

    题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...

  5. POJ 1273 Drainage Ditches题解——S.B.S.

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 67823   Accepted: 2620 ...

  6. POJ 1273 Drainage Ditches -dinic

    dinic版本 感觉dinic算法好帅,比Edmonds-Karp算法不知高到哪里去了 Description Every time it rains on Farmer John's fields, ...

  7. Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )

    题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...

  8. POJ 1273 Drainage Ditches(网络流dinic算法模板)

    POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...

  9. 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches

    Drainage Ditches 题目抽象:给你m条边u,v,c.   n个定点,源点1,汇点n.求最大流.  最好的入门题,各种算法都可以拿来练习 (1):  一般增广路算法  ford() #in ...

随机推荐

  1. Cordova - 使用Cordova开发iOS应用实战1(配置、开发第一个应用)

    Cordova - 使用Cordova开发iOS应用实战1(配置.开发第一个应用) 现在比较流行使用 html5 开发移动应用,毕竟只要写一套html页面就可以适配各种移动设备,大大节省了跨平台应用的 ...

  2. scala 学习笔记(01) 函数定义、分支、循环、异常处理、递归

    package yjmyzz import scala.io.StdIn object ScalaApp { def main(args: Array[String]) { println(" ...

  3. UML:类图复习-鸡生蛋,蛋生鸡

    这是前一阵<高级软件工程>课堂上,老师随堂出的一道讨论题,随手贴在这里: ps: 今天是520,正好聊一些OoXx,关于爱的扯淡话题:) 题目:“鸡生蛋,蛋孵鸡”,世间万物生生不息,如何用 ...

  4. 大圆满的精髓–肯•威尔伯(KEN WILBER)

    作者:肯·威尔伯(Ken Wilber),目前被公认为是“后人本心理学”的最重要的思想家.理论家和发言人,其影响已经跨越了心理学领域,波及哲学和神学领域.由于肯·威尔伯在意识领域的研究极富基础性和开创 ...

  5. Web服务器磁盘满故障

    问题: 硬盘显示被写满,但是用du -sh /*查看时占用硬盘空间之和还远小于硬盘大小,即找不到硬盘分区是怎么被写满的.今天下午接到同事紧急求助,说生产线服务器硬盘满了.该删的日志都删掉了.可空间还是 ...

  6. C++ vector用法

    在c++中,vector是一个十分有用的容器,下面对这个容器做一下总结. 1 基本操作 (1)头文件#include<vector>. (2)创建vector对象,vector<in ...

  7. MVC视图引擎优化

    请首先看如下内容: 未找到视图"Index"或其母版视图,或没有视图引擎支持搜索的位置.搜索了以下位置: ~/Views/Home/Index.aspx~/Views/Home/I ...

  8. github page 和 hexo 搭建在线博客

    目录: 安装node.js与git 常用git命令 安装hexo 配置hexo hexo发布到github 1.安装node.js和git工具 https://nodejs.org/en/ 直接下载安 ...

  9. Socket,TCP/IP,UDP,HTTP,FTP

    1.Socket:套接字,是传输层协议的一种编程API 作用:用于描述IP地址和端口,区分来自不同应用程序的通信,实现数据传输的并发服务 JDK  Socket:在java.net包下有两个类Sock ...

  10. [转]hibernate在eclipse的逆向工程生成hbm.xml和bean类

    原文地址:http://www.xuebuyuan.com/210489.html 以前一直用myelipse,在myeclipse做hibernate逆向工程倒是很顺手了. 可是最近改用eclips ...