POJ 1273 Drainage Ditches题解——S.B.S.
Drainage Ditches
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 67823 | Accepted: 26209 |
Description
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
Output
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<climits>
#define maxn 210
using namespace std;
void find();
void flow();
void update();
struct Edge
{
int c;
int f;
}edge[maxn][maxn];
int n,m;
int s,t;
int residual[maxn][maxn];
int que[maxn*maxn],head,tail;
int pre[maxn];
bool vis[maxn];
int max_flow,min_flow;
void find()
{
int i,cu;
memset(vis,false,sizeof(vis));
memset(residual,,sizeof(residual));
memset(pre,,sizeof(pre));
head=;que[head]=s;pre[s]=s;vis[s]=true;tail=;
while(head<tail&&pre[t]==)
{
cu=que[head];
for(i=;i<=n;i++)
{
if(vis[i]==false)
{
if(edge[cu][i].c-edge[cu][i].f>)
{
residual[cu][i]=edge[cu][i].c-edge[cu][i].f;
pre[i]=cu;que[tail++]=i;vis[i]=true;
}
else if(edge[i][cu].f>)
{
residual[cu][i]=edge[i][cu].f;
pre[i]=cu;que[tail++]=i;vis[i]=true;
}
}
}
head++;
}
}
void flow()
{
int i=t,j;
if(pre[i]==)
{
min_flow=;return;
}
j=0x7fffffff;
while(i!=s)
{
if(residual[pre[i]][i]<j) j=residual[pre[i]][i];
i=pre[i];
}
min_flow=j;
}
void update()
{
int i=t;
if(pre[i]==) return;
while(i!=s)
{
if(edge[pre[i]][i].c-edge[pre[i]][i].f>)
edge[pre[i]][i].f+=min_flow;
else if(edge[i][pre[i]].f>)
edge[pre[i]][i].f+=min_flow;
i=pre[i];
}
}
void solve()
{
s=;t=n;
max_flow=;
while(true)
{
find();flow();
max_flow+=min_flow;
if(min_flow>) update();
else return;
}
}
int main()
{
std::ios::sync_with_stdio(false);
int i,u,v,c;
while(scanf("%d %d",&m,&n)!=EOF)
{
memset(edge,,sizeof(edge));
for(i=;i<m;i++)
{
scanf("%d %d %d",&u,&v,&c);
edge[u][v].c+=c;
}
solve();
printf("%d\n",max_flow);
}
return ;
}
POJ 1273 Drainage Ditches题解——S.B.S.的更多相关文章
- 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 ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- poj 1273 Drainage Ditches 最大流入门题
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
- poj 1273 Drainage Ditches(最大流,E-K算法)
一.Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clove ...
- POJ 1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67387 Accepted: 2603 ...
- POJ 1273 Drainage Ditches -dinic
dinic版本 感觉dinic算法好帅,比Edmonds-Karp算法不知高到哪里去了 Description Every time it rains on Farmer John's fields, ...
- Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )
题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
随机推荐
- ASP.NET MVC 解析模板生成静态页一(RazorEngine)
简述 Razor是ASP.NET MVC 3中新加入的技术,以作为ASPX引擎的一个新的替代项.在早期的MVC版本中默认使用的是ASPX模板引擎,Razor在语法上的确不错,用起来非常方便,简洁的语法 ...
- 在DOS使用SVN之执行命令整理(TortoiseProc.exe)
原文链接: http://www.cnblogs.com/andrew-blog/archive/2012/08/21/SVN_DOS_Commands.html TortoiseSVN因为所有的命令 ...
- 微信扫码支付~官方DEMO的坑~参数不能自定义
返回目录 由于微信在校验参数时采用了“微信服务端”校验,它的参数是前期定义好的,所以用户不能自己添加自定义的参数,你可以把参数写在Attach字段时,作为它的附加参数. 参数和返回值定义如下: pub ...
- swift变量和函数
func getNums()->(Int,Int){ //swift函数可以返回多个变量 ,) } let (a,b) = getNums() //let是常量,一旦赋值后不可改变, var是变 ...
- should be mapped with insert="false" update="false
SSH项目出现了 should be mapped with insert="false" update="false 错误,仔细检查后发现,是两个不同的属性映射了表中的 ...
- Spring2.0-applicationContext.xml中使用el表达式给实体类属性赋值被当成字符串-遁地龙卷风
(-1)写在前面 这两天读<javaweb开发王者归来>,学到Spring的PropertyPlaceholderConfigurer时出现一个问题,我已${jdbc.name}的形式赋值 ...
- entityframework学习笔记--003-使用model first
首先,我个人觉得这(model first 即模型优先)是一个鸡肋似的功能.当赞扬着他的强大的功能的同时,你也会觉得这个功能好像是不是不怎么需要,也很少使用. 1.右键你的项目,选择"添加& ...
- gulp压缩css文件跟js文件
越到最后啊 就越发现,真的很理解那句话 就是自己多学一点一点知识,就少一句问别人的东西 这是多么痛苦的领悟 今天需要压缩css跟js文件 然后不懂啊 就问别人啊 就问啊问啊 然后再上网了解啊了解啊 用 ...
- 前端弹出对话框 js实现 ajax交互
原本计划实现这样一个需求: 前台点击触发某业务动作,需要用户补充信息,不做跳转页面,弹窗的形式进行补充信息. 折腾出来了,但是最终没有用到. 代码还有些毛躁,提供大概实现逻辑. 实现思路: 在窗口铺上 ...
- 深入了解 Authorize 和 AllowAnonymous
深入了解 Authorize 和 AllowAnonymous Chapter 0 - Intro 最近做的一个项目的时候,自定义授权 Attribute 来区分用户权限,我的项目不太大,权限控制也不 ...