最大流(EK)
来源:互联网 发布:网络书籍排行榜2016 编辑:程序博客网 时间:2024/05/17 01:33
Drainage Ditches
Total Submission(s): 9062 Accepted Submission(s): 4254
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.
5 41 2 401 4 202 4 202 3 303 4 10
50代码:#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
using namespace std;
#define inf 0x7fffffff
int map[300][300];
int maxf[300],pre[300];
int n,m;
int min(int x,int y)
{
return x<y?x:y;
}
int bfs()
{
queue<int>q;
int i,hou;
for(i=0;i<=m;i++)
{
pre[i]=-1;
maxf[i]=inf;
}
q.push(1);
pre[1]=0;
while(!q.empty())
{
int qian=q.front();
q.pop();
for(hou=1;hou<=m;hou++)
{
if(map[qian][hou]&&pre[hou]==-1)
{
pre[hou]=qian;
maxf[hou]=min(maxf[qian],map[qian][hou]);
q.push(hou);
}
}
}
if(maxf[m]==inf)
return 0;
return maxf[m];
}
int ek()
{
int max=0;
int index,qian,hou,kejia;
while(kejia=bfs())
{
max+=kejia;
index=m;
while(index!=1)
{
qian=pre[index];
map[qian][index]-=kejia;
map[index][qian]+=kejia;
index=qian;
}
}
return max;
}
int main()
{
int i,u,v,w;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(map,0,sizeof(map));
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&u,&v,&w);
map[u][v]+=w;
}
int ans=ek();
printf("%d\n",ans);
}
return 0;
}
- 最大流(EK)
- 最大流(EK)--poj1149
- EK算法(网络流,最大流)
- 最大流(增广路-EK)poj1273
- 【最大流(EK)】poj 1149 PIGS
- poj1459--Power Network(最大流EK、)
- 最大流网络流(基础EK)
- POJ 3271:Dining(EK最大流)
- hdu3549-Flow Problem(最大流&EK)
- hdu1532-Drainage Ditches(最大流&EK)
- 最大流DFS(EK)算法模板
- 最大流问题(转载)-EK算法
- 最大流EK算法
- 最大流EK算法
- 【POJ1459】【最大流】【EK】
- 【最大流EK】
- 最大流EK
- 最大流-EK
- zookeeper学习笔记一
- 初识Tcpdump
- kettle 总结1 获取某个目录下所有的文件
- 服务器性能调优
- 手机摄像头当做电脑摄像头使用-用于视频聊天
- 最大流(EK)
- iOS上获得MAC地址
- 设计模式
- 青蛙的约会(扩展欧几里得)
- 类的静态变量和 静态方法就可以直接用类名进行访问
- Servlet生命周期
- 使用XShell远程时,界面无法显示中文
- cocos2d-x触摸流程解析
- 宽字符与窄字符的处理