HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532
感觉题意不清楚,不知道是不是个人英语水平问题。本来还以为需要维护入度和出度来找源点和汇点呢,看讨论才知道1就是起点,m就是汇点。。好想把代码写的工程化一点。
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std; const int INF = 0x3f3f3f3f;
int n, m;
int cap[][], flow[][], res[], pre[];
queue<int>que; int Edmonds_Karp()
{
while(!que.empty())
{
que.pop();
}
int flow_sum = ;
while(true)
{
memset(res, , sizeof(res));
res[] = INF;
que.push();
while(!que.empty())
{
int u = que.front();
que.pop();
for(int v = ; v <= m; v++)
{
if(!res[v] && cap[u][v] > flow[u][v])
{
pre[v] = u;
que.push(v);
res[v] = min(res[u], cap[u][v] - flow[u][v]);
}
}
}
if(res[m] == )break;
for(int u = m; u != ; u = pre[u])
{
flow[pre[u]][u] += res[m];
flow[u][pre[u]] -= res[m];
}
flow_sum += res[m];
}
return flow_sum;
} int main()
{
int u, v, w;
while(scanf("%d %d", &n, &m) != EOF)
{
memset(cap, , sizeof(cap));
memset(flow, , sizeof(flow));
for(int i = ; i < n; i++)
{
scanf("%d %d %d", &u, &v, &w);
cap[u][v] += w;
}
printf("%d\n", Edmonds_Karp());
}
return ;
}
HDU 1532 Drainage Ditches 最大流 (Edmonds_Karp)的更多相关文章
- 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(最大流 EK算法)
题目网址: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 分类: 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) ...
- HDU 1532 Drainage Ditches (最大网络流)
Drainage Ditches Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) To ...
随机推荐
- QTP下载链接
QTP下载链接 QTP官网下载:http://www8.hp.com/us/en/software-solutions/software.html?compURI=1172957#.UNMOQ2_FW ...
- [Whole Web, Node.js, PM2] Configuring PM2 for Node applications
In this lesson, you will learn how to configure node apps using pm2 and a json config file. Let's sa ...
- springMVC项目引入jstl标签库若干问题的总结
中午,不知道动到项目的哪个地方了,之前在联系人列表页面用的好好的jstl标签库突然报错了:<%@taglib prefix="c" uri="http://java ...
- (转载)Ant教程
ant教程(一) 写在所有之前 为了减少阅读的厌烦,我会使用尽量少的文字,尽量明白的表达我的意思,尽我所能吧.作为一个学习者,在我的文章中会存在各种问题,希望热心人指正.目录大概是这样 ant教程 ( ...
- sql2012 新增 OFFSET/FETCH
SQL Server 对行数的排序提供了 TOP 筛选.SQL Server 2012 新增了 OFFSET 筛选. 一.TOP 筛选 如果有 ORDER BY 子句,TOP 筛选将根据排序的结果返回 ...
- javascript-01
1.JavaScript:浏览器脚本语言 2.JavaScript的作用 |-1.进行前端验证 |-2.实现页面的动态效果 3.JavaScript的特点 |-1.和java没有任何关系,官方标 ...
- MongoDB 2.6.x 的安装部署
1. 下载mongodb 2.6.x版本的zip包,在D盘创建目录MongoDB,解压缩到D:\MongoDB目录. 创建数据库目录D:\MongoDB\data,接下来打开命令行窗口,切换到D:\M ...
- 强大的游戏开发工具Unity3D推出2D开发工具,unity将混合3D与2D开发
2013 Unity全球开发者大会(Unite 2013)于2013年8月28日在温哥华隆重开幕,会上Unity全球CEO David Helgason在Keynote上宣布Unity 4.3版本即将 ...
- DLL中导出STL模板类的问题
接上一篇. 上一篇的dll在编译过程中一直有一个警告warning C4251: ‘CLASS_TEST::m_structs’ : class ‘std::vector<_Ty>’ ne ...
- ios NSMethodSignature and NSInvocation 消息转发
1.首先获取消息转发时连个函数内部具体内容 MARK:这里是拿[@"xxxxx" length]调用拿来举例说明 (lldb) po signature <NSMethodS ...