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 ...
随机推荐
- Jsonp跨域访问
很早之前看过好几篇跨域访问的文章,然后做项目的时候基本没有遇到跨域访问的问题.不过该来的还是会来,前些天终于让我遇到了.于是重温了一下原理这些,再进行实战.于是现在也敢通过实战后的一些理解来和大家分享 ...
- es6 中增强的对象字面量
http://www.cnblogs.com/Wayou/p/es6_new_features.html 对象字面量被增强了,写法更加简洁与灵活,同时在定义对象的时候能够做的事情更多了.具体表现在: ...
- svn提交时出现很多乱文件怎么解决
在我们开发项目中的时候经常使用到svn,有时候我们commit的时候回出现很多无用的文件,这些文件就是未版本化的文件,怎么解决这些乱文件的问题呢? svn commit提交的时候有个"sho ...
- java web学习总结(十九) -------------------监听器简单使用场景
一.统计当前在线人数 在JavaWeb应用开发中,有时候我们需要统计当前在线的用户数,此时就可以使用监听器技术来实现这个功能了. 1 package me.gacl.web.listener; 2 3 ...
- 实用SQL语句大全
一.基础 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- ...
- 轻松掌握:JavaScript模板方法模式
模板方法模式 假如我们有一些对象,各个对象之间有一些相同的行为,也有一些不同的行为,这时,我们就可以用模板方法模式来把相同的部分上移到它们的共同原型中(父类),而将不同的部分留给自己各自重新实现. 模 ...
- 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(六)地图搜索模块
config.xml文件的配置如下: <widget label="地图搜索" icon="assets/images/emergency_resource_ove ...
- Centos6_64 rpm打包实践
安装rpmbuild sudo yum install rpm-build 普通用户的配置 /home/you/rpmbuild/ 假设是要构建rpm的目录 先说说rpmbuild有什么用,给一个例子 ...
- 关于csrss.exe和winlogon.exe进程多、占用CPU高的解决办法,有人在暴力破解
关于csrss.exe和winlogon.exe进程多.占用CPU高的解决办法 最近VPS的CPU一直处在100%左右,后台管理上去经常打不开,后来发现上远程都要好半天才反映过来,看到任务管理器有多个 ...
- 会话技术( Cookie ,Session)
会话技术: 会话:浏览器访问服务器端,发送多次请求,接受多次响应.直到有一方断开连接.会话结束. 解决问题:可以使用会话技术,在一次会话的多次请求之间共享数据. ...