【网络流】POJ1273 Drainage Ditches
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 78671 | Accepted: 30687 |
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
题解
网络流模板题。。。
dinic求最大流
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define inf 1<<30
using namespace std; struct edge{
int to,ne,cap;
}e[]; int n,m,s,t,a,b,c,ans,ecnt;
int head[],layer[];
queue<int> q; void add(int x,int y,int z)
{
e[++ecnt].to=y;e[ecnt].cap=z;e[ecnt].ne=head[x];head[x]=ecnt;
e[++ecnt].to=x;e[ecnt].cap=;e[ecnt].ne=head[y];head[y]=ecnt;
} bool bfs()
{
//while(!q.empty())q.pop();
q.push(s);
for(int i=;i<=m;++i)layer[i]=;
layer[s]=;
while(!q.empty())
{
int d=q.front();
q.pop();
for(int i=head[d];i;i=e[i].ne)
{
int dd=e[i].to;
if(e[i].cap>&&layer[dd]==)
{
layer[dd]=layer[d]+;
q.push(dd);
}
}
}
return layer[t];
} int dfs(int x,int val)
{
if(val==||x==t)return val;
int ret=;
for(int i=head[x];i;i=e[i].ne)
{
int dd=e[i].to;
if(e[i].cap>&&layer[dd]==layer[x]+)
{
int tmp=dfs(dd,min(val,e[i].cap));
ret+=tmp;
val-=tmp;
e[i].cap-=tmp;
e[(i-)^+].cap+=tmp;
}
}
return ret;
} void dinic()
{
while(bfs())
{
ans+=dfs(s,inf);
}
} int main()
{
while(~scanf("%d%d",&n,&m))
{
ecnt=;ans=;
memset(head,,sizeof(head));
for(int i=;i<=n;++i)
{
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
}
s=;t=m;
dinic();
printf("%d\n",ans);
}
}
【网络流】POJ1273 Drainage Ditches的更多相关文章
- poj1273 Drainage Ditches Dinic最大流
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 76000 Accepted: 2953 ...
- POJ1273 Drainage Ditches (网络流)
Drainage Ditches Time Limit: 1000MS Memor ...
- poj1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68414 Accepted: 2648 ...
- POJ-1273 Drainage Ditches 最大流Dinic
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...
- 2018.07.06 POJ1273 Drainage Ditches(最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Description Every time it rains on Farmer J ...
- POJ1273:Drainage Ditches(最大流入门 EK,dinic算法)
http://poj.org/problem?id=1273 Description Every time it rains on Farmer John's fields, a pond forms ...
- poj-1273 Drainage Ditches(最大流基础题)
题目链接: Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67475 Accepted ...
- 网络流入门 Drainage Ditches
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission(s) ...
- [Poj1273]Drainage Ditches(网络流)
Description 给图,求最大流 最大流模板题,这里用dinic Code #include <cstdio> #include <cstring> #include & ...
随机推荐
- Android内核sysfs中switch类使用实例
Android内核sysfs中switch类使用实例 最终在这个周末,能够干点自己想要干的事了. 由我这个二流的内核驱动开发人员来解析一下sysfs中的switch类.先猜測一下来历,在普通的嵌入式L ...
- 迪杰斯特拉/dijkstra 算法模板(具体凝视)
#include <iostream> #include <malloc.h> #include <cstring> #include <stack> ...
- 【CODEFORCES】 A. Dreamoon and Sums
A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...
- 六、Spring Boot Controller使用
在Controller中使用 @RestController 注解,该注解是spring 4.0引入的.查看源码可知其包含了 @Controller 和 @ResponseBody 注解.我们可以理解 ...
- Uva 01124, POJ 3062 Celebrity jeopardy
It's hard to construct a problem that's so easy that everyone will get it, yet still difficult enoug ...
- IDEA+PHP+XDebug调试配置
XDebug调试配置 临时需要调试服务器上的PHP web程序,因此安装xdebug,下面简单记录 安装xdebug 下载最新并解压 wget https://xdebug.org/files/xde ...
- HTML5 Canvas:初始Canvas
Canvas ,HTML 5中引入它,可以做很多事情:画图.动画.游戏开发等等. Canvas 元素 Canvas 中文翻译为:画布. <canvas id=”yourCanvasId” wid ...
- 为什么在有的服务器上禅道、蝉知安装会报错? 之理解MySQL的SQL_MODE
最近用蝉知的CMS 建站比较多,感觉蛮顺手的,但在给客户安装的时候却会出现安装报错,其原因也很简单 查看了一下他们的install.sql文件中,有些时间字段的默认值是0000-00-00 00:00 ...
- ES6的数据类型
首先ES6包含了ES5里面的数据类型,有undefined,null,boolean,String,Number,Object,而ES6又新增了一种数据类型是Symbol,这种的Symbol数据类型是 ...
- iOS Block的简单使用以及__block 和static修饰变量
简单的代码总结,不足之处多多指教. //简单的使用 -(void)blockOne{ ; int(^BlockOne)(int) = ^(int num2) { return number*num2; ...