博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
queue标号hdu1532 Drainage Ditches
阅读量:7223 次
发布时间:2019-06-29

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

在写这篇文章之前,xxx已经写过了几篇关于改queue标号主题的文章,想要了解的朋友可以去翻一下之前的文章

    

Drainage Ditches

    

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
 
 
#include
#include
#include
using namespace std;const int MAXN=200;const int INF=(1<<29);int flow[MAXN][MAXN];//容量制约int pre[MAXN];//前驱int dalta[MAXN];//改变量int flag[MAXN];//是不是已标号int queue[MAXN],front,rear;int n,m;int EK(){ int i,j,maxflow; maxflow=0; while(1) { for(i=1;i<=m;i++) flag[i]=0; front=rear=0; queue[rear++]=1; flag[1]=1; dalta[1]=INF; pre[1]=1; while(front!=rear&&!flag[m]) { int v=queue[front++]; for(i=1;i<=m;i++) { if(flag[i]) continue; if(flow[v][i]) { dalta[i]=min(dalta[v],flow[v][i]); pre[i]=v; flag[i]=1; queue[rear++]=i; } } } if(!flag[m]) break; maxflow+=dalta[m]; i=m; while(i!=1) { flow[pre[i]][i]-=dalta[m]; flow[i][pre[i]]+=dalta[m]; i=pre[i]; } } return maxflow;}int main(){ int si,ei,ci; while(~scanf("%d%d",&n,&m)) { for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) flow[i][j]=0; while(n--) { scanf("%d%d%d",&si,&ei,&ci); flow[si][ei]+=ci;//注意有平行边 } printf("%d\n",EK()); } return 0;}

文章结束给大家分享下程序员的一些笑话语录: 手机终究会变成PC,所以ip会比wm更加畅销,但是有一天手机强大到一定程度了就会发现只有wm的支持才能完美享受。就好比树和草,草长得再高也是草,时间到了条件成熟了树就会窜天高了。www.ishuo.cn

--------------------------------- 原创文章 By

queue和标号
---------------------------------

转载地址:http://oyzfm.baihongyu.com/

你可能感兴趣的文章
Java核心(五)深入理解BIO、NIO、AIO
查看>>
使用ELK构建分布式日志分析系统
查看>>
react组件的生命周期
查看>>
笔记-SSZipArchive使用以及遇到的问题
查看>>
了解webpack-4.0版本(一)
查看>>
如何培养良好的编程风格
查看>>
Go channel 实现归并排序中的 merge 函数
查看>>
Handler消息机制
查看>>
Dart4Flutter - 不可变性
查看>>
Android OkHttp简易使用
查看>>
Netty Channel源码分析
查看>>
设计模式学习之生成器模式
查看>>
初来乍到
查看>>
(二)构建dubbo分布式平台-平台功能导图
查看>>
promise原理就是这么简单
查看>>
用canvas实现一个colorpicker
查看>>
进击的 JavaScript(四) 之 闭包
查看>>
基于 HTML5 WebGL 的 3D 机房
查看>>
前端CORS请求梳理
查看>>
第八周Swift总结
查看>>