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 ...
随机推荐
- AndroidPN中的心跳检测
在AndroidPN客户端里存在着心跳检测功能.就是每隔一段时间客户端向服务器端发送一个消息,以检测连接是否正常,发送的消息内容为: <presence id="h09Ke-13&qu ...
- VS C# 快捷键
解决VS2010中工具箱的的不见的问题:按快捷键Ctrl+Alt+X 全屏:Shift+Alt+Enter注释选定内容:Ctrl+E+C/Crtr+E+U代码格式化:ctrl+E+F ======== ...
- 嵌入式Linux-GNU Make 使用手册(中译版)
GNU Make 使用手册(中译版) 翻译:于凤昌 译者注:本人在阅读Linux源代码过程中发现如果要全面了解Linux的结构.理解Linux的编程总体设计及思想必须首先全部读通Linux源代码中各级 ...
- Word转换为图片PDF
1. Word转换为PDF,程序很多,但转换后的PDF,还可以复制,虽可以加密禁止复制,但市场上太多的PDF,还可以把PDF转换Word等其他格式,很容易被别人利用和剽窃,即便是PDF加 ...
- Modify the average program to promote for intergers repeatedly.stop when a nagetive number is entere
#include<stdio.h> int main(void) { intcount ,sum,aninterger; printf("enterthe interger an ...
- HTTP请求、响应报文格式
HTTP请求报文格式: HTTP请求报文主要由请求行.请求头部.空行以及请求正文4部分组成 1,请求行由3部分组成,分别为:请求方式,URI(注意这里不是URL)以及协议版本组成,之间由空格分隔 请求 ...
- SQLhepler用法
1. 将SQLhepler添加进来,命名空间导进来. using Microsoft.ApplicationBlocks.Data; 2. 做连接类DBconnection: public class ...
- (Entity FrameWork)Code First to an Existing Database
Pre-Requisites You will need to have Visual Studio 2010 or Visual Studio 2012 installed to complete ...
- c#之内置类型
内置类型:就是.NET Framework System命名空间中写好的类型. 下面看看C#都有哪些内置类型 上面的内置类型,除了string和object外,其他的都被称作简单类型.也可以把左边的看 ...
- .NET客户端下载SQL Server数据库中文件流保存的大电子文件方法(不会报内存溢出异常)
.NET客户端下载SQL Server数据库中文件流保存的大电子文件方法(不会报内存溢出异常) 前段时间项目使用一次性读去SQL Server中保存的电子文件的文件流然后返回给客户端保存下载电子文件, ...