博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1273 Drainage Ditches
阅读量:5821 次
发布时间:2019-06-18

本文共 3248 字,大约阅读时间需要 10 分钟。

Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 50321   Accepted: 19105

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 41 2 401 4 202 4 202 3 303 4 10

Sample Output

50

Source

 
1 //472K    0MS    C++    1220B    2013-10-29 10:47:25 2 /* 3  4     题意: 5         给一个图,求最大流 6      7     网络流最大流: 8         第一题最大流..模板了EK算法.. 9          10 */11 #include
12 #include
13 #define inf 0x7ffffff14 using namespace std;15 int c[205][205]; //容量 16 int flow[205][205]; //流量 17 int n,m;18 int f;19 void Edmondes_Karp()20 {21 int la[205]; //允许的最大调整量 22 int pre[205]; //前驱 23 queue
Q;24 memset(flow,0,sizeof(flow));25 f=0;26 while(true){27 memset(la,0,sizeof(la));28 la[1]=inf;29 Q.push(1);30 while(!Q.empty()){31 int u=Q.front();32 Q.pop();33 for(int v=1;v<=m;v++){34 if(!la[v] && c[u][v]>flow[u][v]){35 pre[v]=u;36 Q.push(v);37 la[v]=min(la[u],c[u][v]-flow[u][v]);38 }39 }40 }41 if(la[m]==0) break; //不存在增广轨 42 for(int u=m;u!=1;u=pre[u]){ //调整增广轨 43 flow[pre[u]][u]+=la[m];44 flow[u][pre[u]]-=la[m];45 }46 f+=la[m];47 }48 }49 int main(void)50 {51 int s,e,c0;52 while(scanf("%d%d",&n,&m)!=EOF)53 {54 memset(c,0,sizeof(c));55 for(int i=0;i

 

转载于:https://www.cnblogs.com/GO-NO-1/articles/3393920.html

你可能感兴趣的文章
【368】相关术语说明
查看>>
ASP.NET的必须知道的东东(HttpModule,HttpHandler)
查看>>
linux---finger命令
查看>>
Artech的MVC4框架学习——第四章Model元数据的解析
查看>>
“将截断字符串或二进制数据”错误分析
查看>>
html5 页面总结
查看>>
matlab练习程序(Hilbert图像置乱)
查看>>
【WP之一】]独立存储
查看>>
关于网页关闭的弹窗
查看>>
线段树练习
查看>>
【2019-06-04】内心的纠结
查看>>
JSP2.0自定义标签
查看>>
aop的概念以及 cglib-nodep-2.1_3.jar第三方jia包动态代理使用
查看>>
Qin Shi Huang's National Road System HDU - 4081(树形dp+最小生成树)
查看>>
nohup和&后台运行,进程查看及终止
查看>>
linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题]
查看>>
ORACLE推导参数Derived Parameter介绍
查看>>
有趣的博客小工具
查看>>
Java中由于数据太大自动转换成科学计数法解决方式
查看>>
JS BOM DOM对象 select联动 计时器 时间 css操作 节点(标签 ) 查找标签 {前端基础之BOM和DOM}...
查看>>