Poj(1273),最大流,EK
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 69355 | Accepted: 26873 |
Description
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
Output
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50
Source
#include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f int cap[][];
int flow[][];
int pre[]; int main()
{
//freopen("input.txt","r",stdin);
int n,m; while(scanf("%d%d",&m,&n)!=EOF)
{
memset(cap,,sizeof(cap));
for(int i=; i<m; i++)
{
int a,b,value;
scanf("%d%d%d",&a,&b,&value);
cap[a][b] += value;
} memset(flow,,sizeof(flow));
queue<int> Q; int node[];
int ans = ;
while(true)
{
Q.push();
memset(node,,sizeof(node));
node[] = INF;
int u;
while(!Q.empty())
{
u = Q.front();
Q.pop();
for(int i=; i<=n; i++)
{
if(!node[i]&&cap[u][i]>flow[u][i])
{
Q.push(i);
node[i] = min(node[u],cap[u][i]-flow[u][i]);
pre[i] = u;
}
}
}
if(node[n]==)
break; for(u = n; u!=; u=pre[u])
{
flow[pre[u]][u] +=node[n];
flow[u][pre[u]] -=node[n];
}
ans+=node[n];
} printf("%d\n",ans);
}
return ;
}
Poj(1273),最大流,EK的更多相关文章
- UVA 820 --- POJ 1273 最大流
找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...
- poj 1273 最大流
题目链接:http://poj.org/problem?id=1273 a.EK算法:(Edmond-Karp): 用BFS不断找增广路径,当找不到增广路径时当前流量即为最大流. b.dinic算法: ...
- [转载 ]POJ 1273 最大流模板
转载 百度文库花了5分下的 不过确实是自己需要的东西经典的最大流题POJ1273 ——其他练习题 POJ3436 . 题意描述: 现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给 ...
- poj 1273最大流dinic算法模板
#include<stdio.h> #include<string.h> #define N 300 #define inf 0x7fffffff #include<qu ...
- poj 1273 最大流入门
明天再拍一遍 #include <iostream> #include <queue> using namespace std; ; const int INF = 0x7FF ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
- poj 3281 最大流+建图
很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很 ...
- 最大流EK和Dinic算法
最大流EK和Dinic算法 EK算法 最朴素的求最大流的算法. 做法:不停的寻找增广路,直到找不到为止 代码如下: @Frosero #include <cstdio> #include ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
随机推荐
- 快速搭建企业subversion
快速搭建企业subversion 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们公司用的版本控制控制系统就是subversion(简称SVN),不得不说这是一款比较好使的管理工 ...
- 2-sat按照最小字典序输出可行解(hdu1814)
Peaceful Commission Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu1251(字典树)
统计难题(hdu1251) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Tota ...
- Java基础(33):StringBuilder的方法与应用实例(String相关类)
Java 中的 StringBuilder 类的常用方法 重要的事情说三遍: 在需要频繁对字符串进行修改操作时使用 StringBuilder 的效率比 String 要高 在需要频繁对字符串进行修改 ...
- Java线程总结
在java中要想实现多线程,有两种手段,一种是继续Thread类,另外一种是实现Runable接口. 对于直接继承Thread的类来说,代码大致框架是: class 类名 extends Thread ...
- jsp页面指令
JSP中共有三个指令: (1)page: 用于定义JSP文件中的全局属性 (2)include: 用于在JSP页面中包含另外一个文件的内容 (3)taglib: 此指令能够让用户自定义新的标签 第三个 ...
- Android 5.0新特性了解(二)----RippleEffect
1.本文介绍的是Android5.0中其中一个炫酷的效果,点击水波纹扩散效果( RippleEffect),以下介绍的实现方式都是调用Android5.0的新API,并非自定义实现,所以支持在Andr ...
- paper 59:招聘
借Valse宝地发条招聘广告:D[腾讯优图]技术大咖招聘 欢迎各位技术大咖尤其应届优秀毕业生投递简历.简历投递:youtu@tencent.com简历投递,邮件标题请按照以下格式:[腾讯_上海_招聘 ...
- css 标签 清除浮动
.clearfloat:after{content: "";clear:both;display: block;}
- zw版【转发·台湾nvp系列Delphi例程】HALCON SetGray
zw版[转发·台湾nvp系列Delphi例程]HALCON SetGray SetGray_Delphi.PNG unit Unit1;interfaceuses Windows, Messages, ...