博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)
阅读量:5869 次
发布时间:2019-06-19

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

Drainage DitchesHal Burch

Time Limit 1000 ms
Memory Limit 65536 kb
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. Note however,
that there can be more than one ditch between two intersections.
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
Input file contains multiple test cases.
In a test case:
Line 1: 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.
Line 2..N+1: Each of 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,One line with 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
source
USACO 4.2

题意:就是给出各个边的最大流量,和起点终点,求最大流。

   Edmonds-Karp 增广路算法

Code:

 

//Edmondes-Karp#include 
#include
#include
#define INF 0x7fffffffusing namespace std;queue
q;const int maxn = 200;int n, m, ans;int next[maxn+10], p[maxn+10], f[maxn+10][maxn+10], cap[maxn+10][maxn+10];int Edmondes_Karp(int s, int t) { int ans = 0, v, u; queue
q; memset(f,0,sizeof(f)); while(true) { memset(p,0,sizeof(p)); p[s] = INF; q.push(s); while(!q.empty()) { //BFS找增广路 int u = q.front(); q.pop(); for(v=1; v<=m; v++) if(!p[v]&&cap[u][v]>f[u][v]) { //找到新节点v next[v] = u; //记录v的父亲,并加入FIFO队列 q.push(v); p[v] = p[u] < cap[u][v]-f[u][v]?p[u] : cap[u][v] - f[u][v]; //s-v路径上的最小残量 } } if(!p[t]) break; //找不到增广路,则当前流已经是最大流 for(u=t; u!=s; u= next[u]) { //从汇点往回走 f[next[u]][u] +=p[t];//更新正向流量 f[u][next[u]] -=p[t];//更新反向流量 } ans += p[t]; //更新从s流出的总流量 } return ans;}int main() { int i, k, k1, k2, k3; while(~scanf("%d%d",&n,&m)) { memset(cap,0,sizeof(cap)); for(i=1; i<=n; i++) { scanf("%d%d%d",&k1,&k2,&k3); cap[k1][k2] +=k3; } printf("%d\n",Edmondes_Karp(1,m) ); } return 0;}

 

 

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

你可能感兴趣的文章
JVM面试真题集
查看>>
简单好看的文本动画效果
查看>>
老菜鸟分析 Vue 的观察-订阅模式:数据变化之后是如何更新页面的呢?
查看>>
Spring Cloud Eureka 服务治理
查看>>
module.exports与export那些事儿
查看>>
设置UISearchController的UISearchBar背景色颜色渐变
查看>>
测者的测试技术手册:自动的自动化EvoSuite 自动生成JUnit的测试用例
查看>>
手把手教你用Node爬取国家统计局最新省市区数据并生成一个JSON文件
查看>>
element-ui深入浅出 v-loading指令
查看>>
ES6对象解构(常用)
查看>>
centos搭建php部署环境
查看>>
Kotlin探究之旅--凯撒加密
查看>>
层次数据结构的数据表设计
查看>>
前端测试-大酱的冬季前端之旅第一游
查看>>
10 种最常见的 Javascript 错误(频率最高)
查看>>
设计模式学习专栏七--------外观模式
查看>>
上海招聘职位信息
查看>>
3-25 周末总结
查看>>
学习vue笔记
查看>>
IDE顺手设置
查看>>