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) ...
随机推荐
- rk3188 双屏异显分析
首先是android层: PhoneWindow.java 中加入了GestureDetector成员, 来实现全局滑屏手势监听 onFling方法中,调用了mDecor.getRootWindo ...
- SVN库迁移整理方法----官方推荐方式
以下是subversion官方推荐的备份方式. 关闭所有运行的进程,并确认没有程序在访问存储库(如 httpd.svnserve 或本地用户在直接访问). 备份svn存储库 #压缩备份 svnadmi ...
- Qt 模拟鼠标点击(QApplication::sendEvent(ui->pushbutton, &event0);)
QPoint pos(0,0);QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt ...
- centos shell脚本编程1 正则 shell脚本结构 read命令 date命令的用法 shell中的逻辑判断 if 判断文件、目录属性 shell数组简单用法 $( ) 和${ } 和$(( )) 与 sh -n sh -x sh -v 第三十五节课
centos shell脚本编程1 正则 shell脚本结构 read命令 date命令的用法 shell中的逻辑判断 if 判断文件.目录属性 shell数组简单用法 $( ) 和$ ...
- Centos安装自定义布局才能自己划分各个区的大小ctrl+z ,fg ,route -n ,cat !$ ,!cat ,XShell 设置, ifconfig CentOS远程连接 Linux中的输入流 第一节课
Centos安装自定义布局才能自己划分各个区的大小ctrl+z ,fg ,route -n ,cat !$ ,!cat ,XShell 设置, ifconfig CentOS远程连接 Linux中 ...
- JAVA 线程状态转换
Thread类中State枚举定义: public enum State { /** * Thread state for a thread which has not yet started. */ ...
- Thymeleaf使用说明
Thymeleaf使用说明 javascript操作: a.<script type="text/javascript" th:inline="javascript ...
- (10)场景转换(Transitions)
Cocos2d-x最爽的一个特性之一就是提供了在两个不同场景之间直接转换的能力.例如:淡入淡出,放大缩小,旋转,跳动等.从技术上来说,一个场景转换就是在展示并控制一个新场景之前执行一个转换效果. 场景 ...
- devise 自定义手机号登录
user model中配置 validates_uniqueness_of :phone def email_required? false end 修改user migration文件,给phone ...
- 2018-2019 ACM-ICPC, Asia Seoul Regional Contest
ProblemA Circuits Solved. 题意: 有$n$个矩形,可以放两条平行与$x$轴的线,求怎么放置两条无线长的平行于$x$轴的线,使得他们与矩形相交个数最多 如果一个矩形同时与两条线 ...