POJ 1273:Drainage Ditches 网络流模板题
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 63339 | Accepted: 24434 |
Description
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
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
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50
给了M个池塘,N个水渠,以及每个水渠连接的两个点和水渠的容量。(编号1为源点,编号M为汇点)。求整个网络中最大能流的水的流量。
网络流模板题。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; const int sum = 201;
const int INF = 99999999;
int cap[sum][sum],flow[sum][sum],a[sum],p[sum]; int N,M; void Edmonds_Karp()
{
int u,t,start=1,result=0;
queue <int> s;
while(s.size())s.pop(); while(1)
{
memset(a,0,sizeof(a));
memset(p,0,sizeof(p)); a[1]=INF;
s.push(1); while(s.size())
{
u=s.front();
s.pop(); for(t=1;t<=M;t++)
{
if(!a[t]&&flow[u][t]<cap[u][t])
{
s.push(t);
p[t]=u;
a[t]=min(a[u],cap[u][t]-flow[u][t]);//要和之前的那个点,逐一比较,到M时就是整个路径的最小残量
}
}
}
if(a[M]==0)
break;
result += a[M]; for(u=M;u!=1;u=p[u])
{
flow[p[u]][u] += a[M];
flow[u][p[u]] -= a[M];
}
}
cout<<result<<endl;
} int main()
{
int i,u,v,value;
while(scanf("%d%d",&N,&M)==2)
{
memset(cap,0,sizeof(cap));
memset(flow,0,sizeof(flow)); for(i=1;i<=N;i++)
{
scanf("%d%d%d",&u,&v,&value);
cap[u][v] += value;
}
Edmonds_Karp();
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1273:Drainage Ditches 网络流模板题的更多相关文章
- poj 1273 Drainage Ditches (网络流 最大流)
网络流模板题. ============================================================================================ ...
- POJ 1273 Drainage Ditches (网络流Dinic模板)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- USACO 4.2 Drainage Ditches(网络流模板题)
Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...
- POJ 1273 Drainage Ditches 网络流 FF
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 74480 Accepted: 2895 ...
- poj 1273 Drainage Ditches 网络流最大流基础
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59176 Accepted: 2272 ...
- HDU 1532 Drainage Ditches(网络流模板题)
题目大意:就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速, 本题就是让你求出最大流速,无疑要运用到求最大流了.题中m为水沟数, ...
- POJ 1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67387 Accepted: 2603 ...
- poj 1273 Drainage Ditches(最大流)
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- POJ 1273 Drainage Ditches (网络最大流)
http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
随机推荐
- 【微信小程序】数组操作
Page({ data: { list:[{ id:1, name:'应季鲜果', count:1 },{ id:2, name:'精致糕点', count:6 },{ id:3, name:'全球美 ...
- sql 经纬度范围检索(谷歌方案)
SELECT id, ( * acos ( //公里: 6371 英里: 3959 cos ( radians(78.3232) ) * cos( radians( 数据库纬度字段) ) * cos( ...
- 结题报告:luogu P2014
题目链接:P2014 选课 简单的树形\(dp\),借助\(dfs\)实现. 一般的树形\(dp\)数组是需要二维的,其中一维记录节点(编号或父/子节点的状态(有时三维)),另一维记录权值或计数. 重 ...
- 02.Delphi通过接口实现多重继承
uSayHello类如下: unit uSayHello; interface type // 接口 IGreetable = interface ['{D91DDE09-0FC4-4FE9-AE0D ...
- leetcode102 Binary Tree Level Order Traversal
""" Given a binary tree, return the level order traversal of its nodes' values. (ie, ...
- vue-cli 局域网可访问配置
vue-cli 使用官方脚手架搭建以后,本地的config配置已经没有了,默认打开localhost,无法ip访问 只要修改项目目录配置和防火墙配置 1.在项目根目录下面加一个文件vue.config ...
- 对上一篇Logstash的补充
主要补充内容: 1.同步多表 2.配置的参数个别说明 3.elasticsearch的"_id"如果有相同的,那么会覆盖掉,相同"_id"的数据只会剩下最后一条 ...
- Codeforces 448C:Painting Fence 刷栅栏 超级好玩的一道题目
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
- 【docker】docker持续集成CI/持续部署CD
持续集成(CI) 持续集成(Continuous integration)是一种流行的软件开发实践.集成是指开发将自己本地的代码提交到git等远端仓库上,那么持续集成就是每天多次提交,提早提交代码. ...
- Arduino - 看门狗定时器(WDT:Watch Dog Timer)
看门狗定时器(WDT:Watch Dog Timer)实际上是一个计数器. 一般给看门狗一个大数,程序开始运行后看门狗开始倒计数. 如果程序运行正常,过一段时间CPU应该发出指令让看门狗复位,令其重新 ...