hdu 1532 Drainage Ditches(最大流模板题)
Drainage Ditches
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14721 Accepted Submission(s):
6968
forms over Bessie's favorite clover patch. This means that the clover is covered
by water for awhile and takes quite a long time to regrow. Thus, Farmer John has
built a set of drainage ditches so that Bessie's clover patch is never covered
in water. Instead, the water is drained to a nearby stream. Being an ace
engineer, Farmer John has also installed regulators at the beginning of each
ditch, so he can control at what rate water flows into that ditch.
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.
first line contains two space-separated integers, N (0 <= N <= 200) and M
(2 <= M <= 200). N is the number of ditches that Farmer John has dug. M is
the number of intersections points for those ditches. Intersection 1 is the
pond. Intersection point M is the stream. Each of the following N lines contains
three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the
intersections between which this ditch flows. Water will flow through this ditch
from Si to Ei. Ci (0 <= Ci <= 10,000,000) is the maximum rate at which
water will flow through the ditch.
rate at which water may emptied from the pond.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define INF 1e9
#define CL(a,b) memset(a,b,sizeof(a))
#define N 205 int n,m;
int mat[N][N];
int pre[N];
bool vis[N]; int xmin(int a,int b)
{
return a>b?b:a;
} bool BFS()
{
int cur;
queue<int> q;
CL(pre,);
CL(vis,false);
vis[]=true; ///true表示这个点已作为起点搜索过了
q.push();
while(!q.empty())
{
cur=q.front();
q.pop();
if(cur == n) return true; ///若搜到了终点,说明这是条增广路径,更新结果
for(int i=; i<=n; i++)
if(!vis[i] && mat[cur][i]) ///是否存在通过的路径
{
q.push(i);
pre[i]=cur;
vis[i]=true;
}
}
return false; ///若已经搜不到终点,则搜索结束
} int max_flow()
{
int ans=;
while()
{
if(!BFS()) return ans;
int Min = INF;
for(int i=n; i!=; i=pre[i])
Min=xmin(Min,mat[pre[i]][i]); ///找到最小的边,残留路径越小,则流量越大
for(int i=n; i!=; i=pre[i])
{
mat[pre[i]][i]-=Min; ///正向边
mat[i][pre[i]]+=Min; ///反向边
}
ans+=Min;
}
} int main()
{
int i,j;
while(~scanf("%d%d",&m,&n))
{
CL(mat,);
int a,b,c;
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
mat[a][b]+=c; ///考虑重边情况,若有两条同样的边,流量为它们的和
}
printf("%d\n",max_flow());
}
return ;
}
hdu 1532 Drainage Ditches(最大流模板题)的更多相关文章
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- hdu 1532 Drainage Ditches(最大流)
Drainage Dit ...
- 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(最大流 EK算法)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1532 思路: 网络流最大流的入门题,直接套模板即可~ 注意坑点是:有重边!!读数据的时候要用“+=”替 ...
- 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 ...
- poj-1273 Drainage Ditches(最大流基础题)
题目链接: Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67475 Accepted ...
- HDU 1532 Drainage Ditches (网络流)
A - Drainage Ditches Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- java 5 绘图GUI
---恢复内容开始--- 绘图的基本原理 color 在awt包里面 字体的相关类 Graphics类常用方法 JFrame 继承JFrame就有主窗口了 Java2D API 绘图的例子 了解Swi ...
- innerhtml outhtml innerText outText 区别
innerHTML获取标签内的HTML outerHTML获取标签及标签内的HTML innerText 设置或获取位于对象起始和结束标签内的文本 outerText 设置(包括标签)或获取(不包括标 ...
- 强强联合 阿里云 RDS for SQL Server 与 金蝶 K/3 WISE 产品实现兼容适配
强强联合 阿里云 RDS for SQL Server 与 金蝶 K/3 WISE 产品实现兼容适配,原K/3 WISE用户通过简单配置就可以无缝搭配RDS SQL Server使用,不需再费时费力自 ...
- Windows 调用OpenProcess失败
OpenProcess 打开|获得进程句柄 函数原型: HANDLE OpenProcess(DWORD dwDesiredAccess,BOOL bInheritHandle,DWORD dwPro ...
- tomcat的日志不输出日志信息的解决方法
1.下载日志jar包,例如:commons-logging-1.1.1.jar.放在tomcat的bin目录下,或者是自己项目的lib包里. 2.修改tomcat的bin目录下面的catalina.b ...
- Oracle企业管理框架
oracle管理服务器 是一个基于java的web构件,该构件是dba用来监视和控制oracle企业框架内各个受管理目标的实际界面 oracle储存库 已收集到并与受管理目标有关的配置和监视信息被存储 ...
- Elasticsearch 启动需要密码?
vagrant@homestead:~$ systemctl disable elasticsearch.service Synchronizing state of elasticsearch.se ...
- PersistGate轻松几步让Redux实现数据持久化
在开发的过程中,数据用redux管理,觉得希望将数据持久化保存,也就是说当用户下一次打开app或网站的时候,我们希望浏览器/APP自动加载出上次的数据,怎么办?有没有一个
- React-FlipOver-Counter(日历翻页)
跟窝一起学习鸭~~ //index.js import React from 'react'; import ReactDOM from 'react-dom'; import './index.cs ...
- HTML5八大特性助力移动WebApp开发
http://www.cocoachina.com/webapp/20150906/13344.html WebApp的实现基础就是HMTL5+JS+CSS3,但是WebApp还是基于浏览器的微网站开 ...