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 ...
随机推荐
- Mysql的时间和日期
datetime 占8个字节 可以显示日期同时显示时间 yyyy-mm-dd hh:mm:ss 显示范围 1000-01-01 00:00:00----9999-12-31 23:59 ...
- 【iCore3 双核心板】例程十七:USB_MSC实验——读/写U盘(大容量存储器)
实验指导书及代码包下载: http://pan.baidu.com/s/1qXt1L0o iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- Final-阶段站立会议4
组名:天天向上 组长:王森 组员:张政.张金生.林莉.胡丽娜 代码地址:HTTPS:https://git.coding.net/jx8zjs/llk.git SSH:git@git.coding.n ...
- Jquery 在页面加载后执行的几种方式
1.$(function(){ $("#a").click(function(){ //adding your code here }); }); 2.$(document) ...
- Thinking in Java——笔记(4)
Controlling Execution true and false Java doesn't allow you to use a number as a boolean. If you wan ...
- linux PPTP VPN客户端安装
转载于http://www.2cto.com/os/201209/157462.html 下载pptp-1.7.2.tar.gz http://pptpclient.sourceforge.net/ ...
- vmware centos6.5 net 配置
使用NAT模式 虚拟机网络连接使用NAT模式,物理机网络连接使用Vmnet8. 虚拟机设置里面——网络适配器,网络连接选择NAT模式. 虚拟机菜单栏—编辑—虚拟网络编辑器,选择Vmnet8 NAT模式 ...
- 混合App 框架选型
个人一直想做个App,但是学习 IOS 的过程发现 原生的做界面还是听麻烦的就放弃了.后来就转到混合式App阵营了 混合式App 定义 Hybrid App(混合模式移动应用)是指介于web-app. ...
- 反向代理在Web渗透测试中的运用
在一次Web渗透测试中,目标是M国的一个Win+Apache+PHP+MYSQL的网站,独立服务器,对外仅开80端口,网站前端的业务系统比较简单,经过几天的测试也没有找到漏洞,甚至连XSS都没有发现, ...
- Oracle SQL基本操作
Oracle数据库基本操作 1.概述 Oracle数据库客户端一般需要安装在服务器上,可以在服务器端操作,一般我们可以用sql developer工具远程连接到数据库,先行建立数据库,然后对表进行增删 ...