题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532

思路分析:问题为最大网络流问题,给定一个有向图,需要求解该有向图的最大网络流,使用EdmondsKarp算法求解;

需要注意输入的边中可能有重边的存在;

代码如下:

#include <queue>
#include <vector>
#include <cstdio>
#include <climits>
#include <cstring>
#include <iostream>
using namespace std; const int MAX_N = + ;
int cap[MAX_N][MAX_N], flow[MAX_N][MAX_N];
int a[MAX_N], p[MAX_N]; inline int Min(int a, int b) { return a < b ? a : b; }
int EdmondsKarp(int ver_num)
{
queue<int> q;
int max_flow = ; memset(flow, , sizeof(flow));
for (;;)
{
memset(a, , sizeof(a));
a[] = INT_MAX;
q.push();
while (!q.empty())
{
int u = q.front();
q.pop();
for (int v = ; v <= ver_num; ++v)
{
if (!a[v] && cap[u][v] > flow[u][v])
{
p[v] = u;
q.push(v);
a[v] = Min(a[u], cap[u][v] - flow[u][v]);
}
}
}
if (a[ver_num] == ) break;
for (int u = ver_num; u != ; u = p[u])
{
flow[p[u]][u] += a[ver_num];
flow[u][p[u]] -= a[ver_num];
}
max_flow += a[ver_num];
}
return max_flow;
} int main()
{
int road_num, ver_num; while (scanf("%d %d", &road_num, &ver_num) != EOF)
{
int ver_1, ver_2, capa; memset(cap, , sizeof(cap));
for (int i = ; i < road_num; ++i)
{
scanf("%d %d %d", &ver_1, &ver_2, &capa);
cap[ver_1][ver_2] += capa;
}
int ans = EdmondsKarp(ver_num);
printf("%d\n", ans);
}
return ;
}

hdoj 1532 Drainage Ditches(最大网络流)的更多相关文章

  1. HDU 1532 Drainage Ditches (网络流)

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

  2. hdoj 1532 Drainage Ditches【最大流模板题】

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

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

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

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

  5. POJ 1273 Drainage Ditches(网络流,最大流)

    Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...

  6. POJ1273 Drainage Ditches (网络流)

                                                             Drainage Ditches Time Limit: 1000MS   Memor ...

  7. POJ_1273 Drainage Ditches 【网络流】

    一.题面 Drainage Ditches 二.分析 网络流的裸题. 1 Edmonds-Karp算法 求解网络流其实就是一个不断找增广路,然后每次找到一条增广路后更新残余网络的一个过程. EK算法主 ...

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

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

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

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

随机推荐

  1. iOS App集成Apple Pay教程(附示例代码)

    苹果在本周一发布了iOS 8.1版本,并正式开放了Apple Pay支付系统.Apple Pay是一个基于NFC的支付系统,不久将被数以万计的线下零售商店予以支持.即便这项科技并不是彻底的突破性进展, ...

  2. Android 快速选择联系人

    Activity 代码如下: /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache ...

  3. 初来乍到--------smarty

    Smarty Day01-----smarty的使用 作用:把php+html分离,程序和美工 使用: 1.下载源码包 2.目录结构 libs 源码文件 Smarty.class.php templa ...

  4. svn添加强制注释,pre-commit结合python

    鉴于组内有些人在提交代码的时候并不写注释,而且没有固定格式,所以准备给svn提交时增加强制注释. 首先找到代码库里的hooks目录,正常建svn库的时候都有这个目录.进入hooks目录,找到pre-c ...

  5. 【LeetCode题意分析&解答】43. Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  6. 有关extern的用法

    1.引言 C++语言的创建初衷是“a better C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同.作为一种欲与C兼容的语言, C++保留了一部分过程式 ...

  7. IOS 特定于设备的开发:监测Retina支持

    近年来,Apple在其旗舰设备上引入了Retina显示屏.根据Apple的说法,他的像素密度非常高,足以使人眼无法区分单独的像素. UIScreen类提供了一种容易的方式,用于监查当前设备是否提供了内 ...

  8. Spring-AOP实践

    Spring-AOP实践 公司的项目有的页面超级慢,20s以上,不知道用户会不会疯掉,于是老大说这个页面要性能优化.于是,首先就要搞清楚究竟是哪一步耗时太多. 我采用spring aop来统计各个阶段 ...

  9. ProFTPD 初探

    ProFTPD:一个Unix平台上或是类Unix平台上(如Linux, FreeBSD等)的FTP服务器程序.

  10. JAVA FILE or I/O学习 - 补充CopyFiles功能

    public class CopyFiles { public static void main(String[] args) { CopyFiles copyFiles = new CopyFile ...