POJ-1273 Drainage Ditches 最大流Dinic
Drainage Ditches
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 65146 Accepted: 25112
Description
Every time it rains on Farmer John’s fields, a pond 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.
Input
The input includes several cases. For each case, the 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.
Output
For each case, output a single integer, the maximum rate at which water may emptied from the pond.
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50
题目大意:草地排水。。。
多组数据,有源有汇。。。。
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
#define maxn 300
int dis[maxn]={0};
int way[maxn][maxn]={0};
int q[maxn*10],h,t;
int n,m,ans;
bool bfs()
{
h=0;t=1;
memset(dis,0xff,sizeof(dis));
dis[1]=0;
q[1]=1;
while (h<t)
{
int j=q[++h];
for (int i=1; i<=n; i++)
{
if (dis[i]<0 && way[j][i]>0)
{
dis[i]=dis[j]+1;
q[++t]=i;
}
}
}
if (dis[n]>0)
return true;
else
return false;
}
int dfs(int loc,int low)
{
int ans=0;
if (loc==n) return low;
for (int i=1; i<=n; i++)
if (way[loc][i]>0 && dis[i]==dis[loc]+1 && (ans=dfs(i,min(loc,way[loc][i]))))
{
way[loc][i]-=ans;
way[i][loc]+=ans;
return ans;
}
return 0;
}
int main()
{
while (~scanf("%d%d",&m,&n))
{
memset(way,0,sizeof(way));
for (int i=1; i<=m; i++)
{
int s,e,water;
scanf("%d%d%d",&s,&e,&water);
way[s][e]+=water;
}
ans=0;
while (bfs())
{
int now;
while (now=dfs(1,0x7fffffff))
ans+=now;
}
printf("%d\n",ans);
}
return 0;
}
POJ-1273 Drainage Ditches 最大流Dinic的更多相关文章
- POJ 1273 Drainage Ditches(最大流Dinic 模板)
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n, ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- poj 1273 Drainage Ditches 最大流入门题
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
- Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )
题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...
- POJ 1273 Drainage Ditches 最大流
这道题用dinic会超时 用E_K就没问题 注意输入数据有重边.POJ1273 dinic的复杂度为O(N*N*M)E_K的复杂度为O(N*M*M)对于这道题,复杂度是相同的. 然而dinic主要依靠 ...
- POJ 1273 Drainage Ditches | 最大流模板
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> #defi ...
- poj 1273 Drainage Ditches(最大流)
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- POJ 1273 Drainage Ditches (网络最大流)
http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- POJ 1273 Drainage Ditches(网络流,最大流)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
随机推荐
- 使用List的addAll()方法请判空指针
在写代码的时候经常会用到List,Set的addAll()方法,但是要注意addAll()方法不能传入空指针. package link.mengya.utils; import link.mengy ...
- VisualStudio2013+EF6+MySql5.5环境下配置
看院子里对EF框架和MySql的配置文章不少,但是几乎出自一篇文章的转载,而且这篇转载的文章的也比较坑爹,下面我将介绍一下我的配置过程: 第一步:安装mysql-connector-net-6.9.9 ...
- [TCPIP]代理arp
一 理论概述 \ 二 实验 实验一:代理arp在nat中的作用(实验发现一下是错的) 实验二.代理arp pc访问服务器想让走路由器(写32bit静态路由),右边的R arp server的时 ...
- C语言 百炼成钢8
//题目22:两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定 //比赛名单.有人向队员打听比赛的名单.a说他不和x比,c说他不和x, z比,请编程序找出 //三 ...
- 一份高级Java招聘要求
搜了一些招聘,发现自己还有很长的路要走啊,学无止境...... 摘一个典型的招聘要求,如下: 1.5年基于java的项目开发经验,2.熟悉基于 J2EE的相关开源技术以及Spring,Struts2, ...
- java内部类 2016年12月13号
1.在外部类的任意位置创建内部类对象的方法: 1)从外部类的非静态方法之外的任意位置创建某个内部类的对象,必须指明这个对象所在的外部类和内部类:OuterClassName.InnerClassNam ...
- Google proto buffer的安装/使用
protobuf安装/使用原本是要在官网上下载的:http://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz可惜已被墙,幸好有好心人提供了以下 ...
- C# log4net 不输出日志
一个新项目,直接用了一些之前的代码,突然跟踪不到日志了.检查发现了原因,特在此记录. log4net的配置文件log4net_config.xml <?xml version="1.0 ...
- 在opencv3中的机器学习算法
在opencv3.0中,提供了一个ml.cpp的文件,这里面全是机器学习的算法,共提供了这么几种: 1.正态贝叶斯:normal Bayessian classifier 我已在另外一篇博文中介 ...
- 在opencv3中实现机器学习之:利用svm(支持向量机)分类
svm分类算法在opencv3中有了很大的变动,取消了CvSVMParams这个类,因此在参数设定上会有些改变. opencv中的svm分类代码,来源于libsvm. #include "s ...