【网络流】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 & ...
随机推荐
- Struts框架的国际化
本文将通过一个详细的实例来展示Struts框架的国际化,使用的版本号是struts1.1. 案例:在一个页面上有一个下拉框,下拉框中有3个国家的语言选项,各自是"中文简体".&qu ...
- C(8)
C语言位运算与文件 本章引言: 在不知不觉中我们的C高速入门系列已经慢慢地接近尾声了,而在这一节中,我们会对 C语言中的位运算和文件进行解析,相信这两章对于一些人来说是陌生的,由于非常多 老师都会跳过 ...
- Xcode6 UIWebView与JavaScript交互(issue fix)
这篇文章中,有介绍UIWebView与JavaScript交互,在UIWebView截获JavaScript请求处理.从app的角度,这是JavaScript的Hook请求. 在Xcode6之前的Ap ...
- zookeeper web ui-->node-zk-browser安装
眼下公司正在使用zookeeper做配置管理和其它工作,在网上找几个zookeeper管理工具,都不尽人意,要么功能不够强大,要么不能友好的浏览zk树形结构.我的想法是zk管理工具,应该有一个树形结构 ...
- Creational模式之Builder模式
1.意图 将一个复杂对象的构建与它表示分离,使得相同的构建过程能够创建不同的表示. 查看很多其它请点击 2.别名 无 3.动机 一个RTF(Rich Text Format)文档交换格式的阅读器应能将 ...
- Liunx的常用命令
常用指令 ls 显示文件或目录 -l 列出文件详细信息l(list) -a 列出当前目录下所有文件及目录,包括隐藏的a(all) mkdir 创建目录 -p 创建目录,若无父目录,则创建p(paren ...
- git命令的使用
git命令行的使用 0. 工作中常使用的命令行(小结) 假设我们工作共同使用的开发分支为dev,我自己的开发分支为dev_cx.安装git,在工作文件夹下打开git bash. $ git check ...
- 什么是JWT(JSON WEB TOKEN)
转自于:http://www.jianshu.com/p/576dbf44b2ae 什么是JWT Json web token(JWT)是为了网络应用环境间传递声明而执行的一种基于JSON的开发标准( ...
- Java中数据类型及其之间的转换(转)
Java中数据类型及其之间的转换 基本的数据类型 基本类型有以下四种:1)int长度数据类型有:byte(8bits).short(16bits).int(32bits).long(64bits).2 ...
- EclipseIDE设置
对于新安装的Eclipse而言要设置: 1.Window-Preferences-General-Workspace,然后分别设置Text file encoding为UTF-8和设置New text ...