HDU1532 Drainage Ditches 网络流EK算法
Drainage Ditches
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
#include<bits/stdc++.h>
#define N 205
#define mes(x) memset(x, 0, sizeof(x));
#define ll __int64
const long long mod = 1e9+;
const int MAX = 0x7ffffff;
using namespace std;
int plat[N][N], n, dir[N], pre[N];
int bfs(int s,int e){
int t, i;
queue<int>q;
memset(dir,,sizeof(dir));
memset(pre,-,sizeof(pre));
pre[s] = s;
dir[s] = ;
q.push(s);
while(!q.empty()){
t = q.front();
q.pop();
for(i=;i<=n;i++){
if(plat[t][i] > &&!dir[i]){//全为正且未走过即扩展
pre[i] = t;
dir[i] = ;
if(i == e) return ;//扩展到终点为止
q.push(i);
}
}
}
return ;//找不到
}
int EK(int s,int e){
int ans=,minn,i;
while(bfs(s,e)){
minn = MAX;
for(i=e;i!=s;i=pre[i])
if(minn > plat[pre[i]][i])
minn = plat[pre[i]][i];
for(i=e;i!=s;i=pre[i]){
plat[pre[i]][i] -= minn;
plat[i][pre[i]] += minn;
}
ans += minn; }
return ans;
}
int main()
{
int m, a, b, c;
while(~scanf("%d%d", &m, &n)){
mes(plat);
while(m--){
scanf("%d%d%d", &a, &b, &c);
plat[a][b] += c;
}
printf("%d\n", EK(,n));;
}
return ;
}
HDU1532 Drainage Ditches 网络流EK算法的更多相关文章
- Drainage Ditches(网络流(EK算法))
计算最大流,EK算法模板题. #include <stdio.h> #include <string.h> #include <queue> using names ...
- HDU-1532 Drainage Ditches,人生第一道网络流!
Drainage Ditches 自己拉的专题里面没有这题,网上找博客学习网络流的时候看到闯亮学长的博客然后看到这个网络流入门题!随手一敲WA了几发看讨论区才发现坑点! 本题采用的是Edmonds-K ...
- HDU1532 Drainage Ditches —— 最大流(sap算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/ ...
- hdu-----(1532)Drainage Ditches(最大流问题)
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU1532_Drainage Ditches(网络流/EK模板/Dinic模板(邻接矩阵/前向星))
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- NYOJ 323 Drainage Ditches 网络流 FF 练手
Drainage Ditches 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Every time it rains on Farmer John's fields, ...
- POJ 1459 网络流 EK算法
题意: 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 2 1 1 2 表示 共有2个节点,生产能量的点1个,消耗能量的点1个, 传递能量的通道2条:(0,1)20 (1,0) ...
- 最大网络流 EK 算法
网络流是什么类型的问题,看一道题目你就知道了 点击打开链接 . 默认具备图论的基本知识,网络流概念比较多,先看看书熟悉一下那些概念.比较好!一个寄出的网络最大流.EK算法写的. 这是一幅网络,求S ...
- POJ 1273 Drainage Ditches (网络流Dinic模板)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
随机推荐
- select的5中子句where,group by, havaing, order by, limit的使用顺序及实例
-- 语法: SELECT select_list FROM table_name [ WHERE search_condition ] [ GROUP BY group_by_expression ...
- LFS初次成功+如何粘贴复制LFS命令
搞了几次LFS,终于成功了,总算舒了一口气. 这次搞LFS用到的资料:LFS文档:http://www.ha97.com/book/lfs-book-6.6/index.html 一份简单的指导文章 ...
- java环境搭建系列:JDK环境变量详细配置
学习java语言,编写java程序,运行java程序,都离不开Java环境的支持,最重要的就是安装JDK,JDK给我提供了java程序的开发环境和运行环境.为了让java程序放在电脑的任意位置都可以执 ...
- 使用CSS将图片转换成黑白(灰色、置灰)z转
小tip: 使用CSS将图片转换成黑白(灰色.置灰) by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.c ...
- Mongo聚合函数
{ "_id" : ObjectId("57301c7e5fd5d6e2afa221d1"), "a" : "张三", ...
- butterknife异常提示:attribute value must be constant
就是因为你的android工程是lib类型的 如: apply plugin: 'com.android.library' android { compileSdkVersion 23 buildTo ...
- python 常用模块 Top200
名次 模块名称 被使用项目数 1 sys 7858 2 os 6983 3 re 5663 4 time 5268 5 random 3339 6 datetime 3310 7 setuptools ...
- Python之路-python(常用模块学习)
模块介绍 time &datetime模块 random os sys shutil shelve xml处理 yaml处理 configparser hashlib re正则表达式 1.模块 ...
- startup.c
在Startup.s文件中包含一个startup的入口函数,该函数为EBOOT的最开始的入口.在系统上电或者冷启动的时候,这是第一个被执行的函数.该函数都是由汇编语言编写的,完成基于硬件平台的最初的初 ...
- java虚拟机内部介绍
一.介绍 java 的内存管理和垃圾回收在某种程度是同一个问题来着.对于java程序员来说,在虚拟机自动内存管理机制的帮助下,不在需要为每一个new操作去写配对的delete/free代码,不容易出现 ...