HDU 1532 Drainage Ditches(最大流 EK算法)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532
思路:
网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替换“=”。
对网络流不熟悉的,给一篇讲解:http://www.cnblogs.com/ZJUT-jiangnan/p/3632525.html。 ✧(≖ ◡ ≖✿)我是看这篇博客才入门的。
代码:
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int inf=;
int n,m;
int mp[][];
int vis[];
int pre[];
void update(int s,int t,int Min){
int k=t;
while (pre[k]!=-) {
mp[k][pre[k]]+=Min;
mp[pre[k]][k]-=Min;
k=pre[k];
}
}
int bfs(int s,int t){
int Min=inf;
memset(vis, , sizeof(vis));
memset(pre, -, sizeof(pre));
queue<int>q;
q.push(s);
vis[s]=;
while (!q.empty()) {
int x=q.front();q.pop();
for (int i=; i<=n; i++) {
if (!vis[i] && mp[x][i]>) {
pre[i]=x;
Min=min(mp[x][i], Min);
q.push(i);
vis[i]=;
}
}
if(pre[t]!=-) return Min;
}
return ;
}
int edmonds_karp(int s,int t){
int Min=-;
int Max=;
while(Min!=){
Min=bfs(s, t);
update(s,t,Min);
Max+=Min;
}
return Max;
}
int main(){
while (scanf("%d%d",&n,&m)!=EOF) {
memset(mp, , sizeof(mp));
for (int i=; i<n; i++) {
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
mp[x][y]+=z;//注意!!
}
printf("%d\n",edmonds_karp(, m));
}
return ;
}
HDU 1532 Drainage Ditches(最大流 EK算法)的更多相关文章
- 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 最大流 (Edmonds_Karp)
题目链接: 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(网络流模板题)
题目大意:就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速, 本题就是让你求出最大流速,无疑要运用到求最大流了.题中m为水沟数, ...
- 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) ...
随机推荐
- tlc549
#include <reg51.h> #include "TLC549.c" code uchar seven_seg[] = {0xc0, 0xf9, 0xa4, 0 ...
- Driect3D初始化演示
初始化Direct3D演示 初始化Driect3D类: #include "Common\d3dApp.h" #include <DirectXColors.h> us ...
- 54 (OC)* 网络七层架构
一:TCP/IP协议 二:七层协议 1:物理层 物理层为设备之间的数据通信提供传输媒体及互连设备,为数据传输提供可靠的环境. 1.1:传输媒体和互连设备 物理层的媒体包括架空明线.平衡 ...
- docker harbor搭建笔记
介绍 Harbor是VMware公司开源的一个用于存储和分发Docker镜像的企业级Registry服务器,以Docker开源的Registry为基础,通过添加一些企业必需的功能特性,例如安全.标识和 ...
- Winform去掉标题栏后移动窗体
第一步:声明全局变量-> private Point _HoverTreePosition; 第二步: #region 隐藏标题栏后移动窗口 private void Form_HoverTr ...
- jdk1.8源码阅读
一.java.lang java的基础类 1.object 所有类的爸爸 registerNatives() Class<?> getClass():返回运行时的类 int hashCod ...
- AsyncLocal和Async原理解读
AsyncLocal 的实现很简单,将AsyncLocal实例和当前线程的值以键值对的形式保存在Thread.CurrentThread.ExecutionContext.m_localValues. ...
- Linux6.x 更换国内比较快的yum源-通用版
----------更换国内比较快的yum源----------- ----------163--------- cd /etc/yum.repos.d mv CentOS-Base.repo Cen ...
- Sentinel Core流程分析
上次介绍了Sentinel的基本概念,并在文章的最后介绍了基本的用法.这次将对用法中的主要流程和实现做说明,该部分主要涉及到源码中的sentinel-core模块. 1.token获取 如上为t ...
- Kurskal算法
Kruskal算法是以边为主要关注对象的最小生成树算法,是最小生成树最佳的算法实现. 其时间复杂度为O(ElogE)(E为边的数量),而Prime算法采用邻接矩阵的方法是O(V^2)(V为顶点数量). ...