HDU-1532 Drainage Ditches (最大流,EK算法模板)
题目大意:最大流的模板题。。。源点是0,汇点是n-1。
代码如下:
# include<iostream>
# include<cstdio>
# include<cmath>
# include<string>
# include<vector>
# include<list>
# include<set>
# include<map>
# include<queue>
# include<cstring>
# include<algorithm>
using namespace std; # define LL long long
# define REP(i,s,n) for(int i=s;i<n;++i)
# define CL(a,b) memset(a,b,sizeof(a))
# define CLL(a,b,n) fill(a,a+n,b) const double inf=1e30;
const int INF=1<<30;
const int N=205; struct Edge
{
int fr,to,c,f;
Edge(int _fr,int _to,int _c,int _f):fr(_fr),to(_to),c(_c),f(_f){}
}; int n,m;
vector<Edge>e;
vector<int>G[N*2];
int a[N*2],p[N*2]; void init()
{
REP(i,0,n) G[i].clear();
e.clear();
} void addEdge(int fr,int to,int cap)
{
e.push_back(Edge(fr,to,cap,0));
e.push_back(Edge(to,fr,0,0));
int len=e.size();
G[fr].push_back(len-2);
G[to].push_back(len-1);
} int maxFlow()
{
int flow=0;
while(1)
{
CL(a,0);
queue<int>q;
q.push(0);
a[0]=INF;
while(!q.empty())
{
int x=q.front();
q.pop();
REP(i,0,G[x].size()){
Edge &edge=e[G[x][i]];
if(!a[edge.to]&&edge.c>edge.f){
p[edge.to]=G[x][i];
a[edge.to]=min(a[x],edge.c-edge.f);
q.push(edge.to);
}
}
if(a[n-1]) break;
}
if(!a[n-1]) break;
for(int u=n-1;u;u=e[p[u]].fr){
e[p[u]].f+=a[n-1];
e[p[u]^1].f-=a[n-1];
}
flow+=a[n-1];
}
return flow;
} int main()
{
int a,b,c;
while(~scanf("%d%d",&m,&n))
{
init();
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
addEdge(a-1,b-1,c);
}
printf("%d\n",maxFlow());
}
return 0;
}
HDU-1532 Drainage Ditches (最大流,EK算法模板)的更多相关文章
- HDU 1532 Drainage Ditches(最大流 EK算法)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...
- POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)
Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...
- hdu 1532 Drainage Ditches (最大流)
最大流的第一道题,刚开始学这玩意儿,感觉好难啊!哎····· 希望慢慢地能够理解一点吧! #include<stdio.h> #include<string.h> #inclu ...
- hdu 1532 Drainage Ditches(最大流)
Drainage Dit ...
- HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 感觉题意不清楚,不知道是不是个人英语水平问题.本来还以为需要维护入度和出度来找源点和汇点呢,看 ...
- poj 1273 && hdu 1532 Drainage Ditches (网络最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53640 Accepted: 2044 ...
- hdu 1532 Drainage Ditches(最大流模板题)
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1532 Drainage Ditches(网络流模板题)
题目大意:就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速, 本题就是让你求出最大流速,无疑要运用到求最大流了.题中m为水沟数, ...
- HDU 1532 Drainage Ditches 分类: Brush Mode 2014-07-31 10:38 82人阅读 评论(0) 收藏
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 用了快1年的MacBook Pro遇到的硬件问题
去年11月7日买的MacBook Pro,到目前快1年了,遇到了3个硬件问题(之前用了5年的Thinkpad在5年内未出现任何硬件问题): 1. 有一次MacBook放在背包中,背包拎在手上落在地上, ...
- Mirror--镜像相关操作
其他相关操作1. 关闭镜像--关闭镜像USE [master]GOALTER DATABASE Demo1 SET PARTNER OFFGO 2. 证服务器--移除见证服务器USE [master ...
- 代码处理 iOS 的横竖屏旋转
一.监听屏幕旋转方向 在处理iOS横竖屏时,经常会和UIDeviceOrientation.UIInterfaceOrientation和UIInterfaceOrientationMask这三个枚举 ...
- centos LAMP第一部分-环境搭建 Linux软件删除方式,mysql安装,apache,PHP,apache和php结合,phpinfo页面,ldd命令 第十九节课
centos LAMP第一部分-环境搭建 Linux软件删除方式,mysql安装,apache,PHP,apache和php结合,phpinfo页面,ldd命令 第十九节课 打命令之后可以输入: e ...
- SqlServer PIVOT函数快速实现行转列,UNPIVOT实现列转行(转)
我们在写Sql语句的时候没经常会遇到将查询结果行转列,列转行的需求,拼接sql字符串,然后使用sp_executesql执行sql字符串是比较常规的一种做法.但是这样做实现起来非常复杂,而在SqlSe ...
- Eclipse中没有javax.servlet和javax.servlet.http包的处理办法
使用Eclips开发JSP也需要这两个包:javax.servlet和javax.servlet.http:若提示没有javax.servlet包则安装如下处理办法解决: 如果你装了Tomacat,那 ...
- Python Web开发之路
Flask相关 1.DBUtils数据库连接池 2.Flask之初体验 3.Flask之WTForms 4.Flask之信号 5.Flask之flask-session 6.Flask之flask-s ...
- 3.5 Templates -- Binding Element Attributes(绑定元素属性)
一.概述 除了正常的文本,你可能还需要你的模板中包含的HTML元素的属性绑定到controller. 1. 例如,设想controller有一个属性包含一个图片的URL: <div id=&qu ...
- #C++初学记录(高精度运算)(加法)
高精度运算 不管是int还是double亦或者long long ,这些定义变量都有数据范围的一定限制,在计算位数超过十几位的数,也就是超过他们自身的数据范围时,不能采用现有类型进行计算,只能自己通过 ...
- 17初识select
多路复用 select 同时监控多个文件描述符的输入输出 <sys/types.h> <sys/times.h> <sys/select.h> int select ...