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 ...
随机推荐
- [Angular 2] Create Angular 2 Porject with Angular CLI
Install: npm i -g angular-cli Create a project: ng new hello-angular2 Run the project: cd hello-angu ...
- mysqld --debug-sync
http://hedengcheng.com/?p=238https://dev.mysql.com/doc/internals/en/debug-sync-facility.html mysqld ...
- 嵌入式Linux-linux连接脚本
嵌入式Linux-linux连接脚本 介绍 每一个链接过程都由链接脚本(linker script, 一般以lds作为文件的后缀名)控制. 链接脚本主要用于规定如何把输入文件内的section放入输出 ...
- MAC地址查询 Linux/Unix操作系统mac地址怎么查
Linux/Unix操作系统熟悉的人都通常是用console命令控制台来进行相应的操作. Linux/Unix操作系统查看网卡mac地址的方法可以通过以下命令获得: 1.ifconfig -a 2. ...
- js中对象的创建
json方式,构造函数方式,Object方式,属性的删除和对象的销毁 <html> <head> <title>js中的对象的创建</title> &l ...
- 腾讯海量数据处理平台TDW
TDW是腾讯海量数据处理平台中最核心的模块,它有以下几个作用: 提供海量的离线计算和存储服务.TDW是腾讯内部规模最大的离线数据处理平台,公司内大多数业务的产品报表.运营分析.数据挖掘等的存储和计算都 ...
- c#常用的一些命名空间
using System.Collections; 有ArrayList;Hashtable;Stack;Queue;DictionaryEntry;等集合 using System.Data; 访问 ...
- (转)HttpHandler与HttpModule的理解与应用
神秘的HttpHandler与HttpModule 大学时候我是从拖控件开始学习 asp.net的,对.net的很多类库对象都不是很了解.所以看到大家写一些个性的asp.net名词,就感觉asp.ne ...
- 20160421javaweb之上传下载小案例---网盘
一.建立数据库: CREATE TABLE IF NOT EXISTS `netdisk` ( `id` ) NOT NULL AUTO_INCREMENT, `uuidname` ) NOT NUL ...
- 周末充电之WPF(一).初试牛刀
追的剧已经赶上更新的速度了,突然觉得一下子就闲了.趁着这点时间,刚好学点 WPF .看到这边,好多人估计得感叹技术宅约等于单身狗,哈哈.好了,赶紧进入学习状态. 关注 WPF 或者说对它感兴趣其实多半 ...