题目链接: 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)的更多相关文章

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

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

  2. hdu 1532 Drainage Ditches (最大流)

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

  3. hdu 1532 Drainage Ditches(最大流)

                                                                                            Drainage Dit ...

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

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

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

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

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

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

  7. HDU 1532 Drainage Ditches (网络流)

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

  8. 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) ...

  9. HDU 1532 Drainage Ditches (最大网络流)

    Drainage Ditches Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) To ...

随机推荐

  1. [Angular 2] Building a Toggle Button Component

    This lesson shows you how to build a Toggle Button in Angular 2 from scratch. It covers using transc ...

  2. iOS 网络编程:XML解析

    1 XML文档结构 1.1 简介 XML 指可扩展标记语言(eXtensible Markup Language).XML 被设计用来传输和存储数据.其非常像HTML的标记语言,但与之不同的是,XML ...

  3. 从数组中随机取n条不重复的数据

    工作中经常遇到有关数组的一些操作 1. 从数据中随机取n条不重复的数据 (PS:下面的S.each是KISSY.each方法,大家可以改为for循环) /* 1 从数组arr中随机取n条不重复的数据 ...

  4. Bootstrap与tab组合,切换菜单实例

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  5. R-大数据分析挖掘(3-R作图)

    R语言绘图功能: 提供实例: demo(graphics)

  6. java struts2自定义调用方法

    一个action里面不只会调用一个方法,肯定会用到其他的方法,也写在同一个action里面. 这里不重点讲解了,就直接上代码 struts.xml <?xml version="1.0 ...

  7. Oracle hextoraw和rawtohex

    Oracle hextoraw和rawtohex [日期:2012-07-17] 来源:Linux社区  作者:adrain_001 [字体:大 中 小]     HEXTORAW  语法: HEXT ...

  8. linux命令打开程序

    evince 打开pdf firefox 打开浏览器

  9. 安卓模拟器"bluestacks"在电脑上的设置.(宽,高)

    可以在手机上找到大量英语学习APP. 习惯使用电脑的朋友,可以安装模拟器来使用这些APP. bluestacks 是一款比较好的模拟器. 但其默认的宽,高,却无法在软件中修改. 找到一个比较好的教程来 ...

  10. PAT_1026 程序运行时间

    问题描述: 要获得一个C语言程序的运行时间,常用的方法是调用头文件time.h,其中提供了clock()函数,可以捕捉从程序开始运行到clock()被调用时所耗费的时间.这个时间单位是clock ti ...