题目大意:最大流的模板题。。。源点是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算法模板)的更多相关文章

  1. HDU 1532 Drainage Ditches(最大流 EK算法)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...

  2. POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)

    Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...

  3. hdu 1532 Drainage Ditches (最大流)

    最大流的第一道题,刚开始学这玩意儿,感觉好难啊!哎····· 希望慢慢地能够理解一点吧! #include<stdio.h> #include<string.h> #inclu ...

  4. hdu 1532 Drainage Ditches(最大流)

                                                                                            Drainage Dit ...

  5. HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 感觉题意不清楚,不知道是不是个人英语水平问题.本来还以为需要维护入度和出度来找源点和汇点呢,看 ...

  6. poj 1273 && hdu 1532 Drainage Ditches (网络最大流)

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53640   Accepted: 2044 ...

  7. hdu 1532 Drainage Ditches(最大流模板题)

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDU 1532 Drainage Ditches (网络流)

    A - Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1532 Drainage Ditches(网络流模板题)

    题目大意:就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速, 本题就是让你求出最大流速,无疑要运用到求最大流了.题中m为水沟数, ...

  10. 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. 阿里云 elastic search 重启 过程

    阿里云 es 重启 elasticsearch  重启 过程 实例变更中   53.13%   准备ECS资源 已完成节点数:4/4, 进度:100%     准备容器服务 进度:100%     变 ...

  2. Spring - Bean Definition Bean定义 给容易提供元数据的3方法

    Spring Bean Definition https://www.tutorialspoint.com/spring/spring_bean_definition.htm The objects ...

  3. Linux学习-->如何通过Shell脚本实现发送邮件通知功能?

    1.安装和配置sendmail 不需要注册公网域名和MX记录(不需要架设公网邮件服务器),通过Linux系统自带的mail命令即可对公网邮箱发送邮件.不过mail命令是依赖sendmail的,所以我们 ...

  4. 【mybatis】认识selectKey

    转:https://mybatis.github.io/mybatis-3/zh/sqlmap-xml.html 对于不支持自动生成类型的数据库或可能不支持自动生成主键 JDBC 驱动来说,MyBat ...

  5. C++ builder 书籍推荐

    china-pub网上书店c++builder书籍专区,本专区专门为c++builder学习者提供目前最为畅销实用的c++builder技术书籍,通过对本专区c++builder书籍的了解,让您学习c ...

  6. #C++初学记录(高精度运算)(加法)

    高精度运算 不管是int还是double亦或者long long ,这些定义变量都有数据范围的一定限制,在计算位数超过十几位的数,也就是超过他们自身的数据范围时,不能采用现有类型进行计算,只能自己通过 ...

  7. ruby中的win32ole使用

    ruby中的win32ole是一个标准库,使用的时候只要添加require 'win32ole'就行. 下面是一段模拟一个登陆的代码 require 'win32ole' ie = WIN32OLE. ...

  8. supervisor安装及其配置

    一.supervisor概述 supervisor是一个c/s系统,被用来在类Unix系统中监控进程状态.supervisor使用python开发. 服务端进程为supervisord,主要负责启动自 ...

  9. java 读CSV 和 Excel

    1.csv和excel读写对比 开发中经常遇到数据导入和导出功能,csv 和 excel是最常见的数据格式,本文比较了下csv和excel读写相同数据的效率: 测试数据格式一 用上面模板数据生成的测试 ...

  10. Python3.6(windows系统)安装pip.whl

    Python3.6(windows系统)安装pip.whl 1,下载whl文件:https://pypi.python.org/pypi/pip#downloads 2,将下载的文件放入Python的 ...