【网络流】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 & ...
随机推荐
- 二叉排序树(BST)构造与应用
二叉排序树(BST)构造与应用 本文取自<数据结构与算法>(C语言版)(第三版).出版社是清华大学出版社. 本博文作为学习资料整理. 源码是VC+ ...
- html页面高度自适应
本文实现的效果是依据浏览器分辨率的不同.页面底端背景色自适应浏览器高度,也就是能够自己主动填充背景色. <script type="text/javascript"> ...
- 翻译:SET NAMES
*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...
- mybatis 基础
前言 MyBatis作为一款持久层的框架,从最初的ibatis更名,经过五六年的发展更新,如今已经更新到了3.4.5版本.MyBatis通过简单的xml或注解配置,就能将接口和Java的对象映射成数据 ...
- springMVC(3)---利用pdf模板下载
springMVC(3)---利用pdf模板下载 在实际开发中,很多时候需要通过把数据库中的数据添加到pdf模板中,然后供客户下载,那我们该如何中呢? 本文主要内容是:用java在pdf模板中加入数据 ...
- go实例之函数
1.可变参数 示例代码如下: package main import "fmt" // Here's a function that will take an arbitrary ...
- HTML的三种布局:DIV+CSS、FLEX、GRID
Div+css布局 也就是盒子模型,有W3C盒子模型,IE盒子模型.盒子模型由四部分组成margin.border.padding.content. 怎么区别这两种模型呢,区别在于w3c中的width ...
- ArcGIS API for JavaScript 4.2学习笔记[6] goTo()地图动画
这是个很有意思的例子,不过例子给的比较复杂,需要查很多API,我会在文章最后给出关键的类和属性解释. 同样发现一个很有意思的事儿:博客园似乎有爬虫,我4号发布的blogs,5号就在百度和google搜 ...
- bzoj 3139: [Hnoi2013]比赛
Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联 赛共N支球队参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支球队各得 ...
- 关于html,css,js三者的加载顺序问题
<head lang="en"> <meta charset="utf-8"> <title></title> ...