POJ 1273 Drainage Ditches (网络最大流)
id=1273
|
Drainage Ditches
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 Sample Output 50 Source |
n条边。m个点,1是源点。m是汇点,给出各有向边容量。求最大流。
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<map>
#include<set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10
#define maxm 207<<2
#define maxn 207 using namespace std; int fir[maxn],d[maxn];
int u[maxm],v[maxm],cap[maxm],flow[maxm],rev[maxm],nex[maxm];
int e_max;
int q[maxm];
int p[maxn];
int n,m; int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/fcbruce/文档/code/t","r",stdin);
#endif // ONLINE_JUDGE while (~scanf("%d %d",&n,&m))
{
e_max=0;
memset(fir,-1,sizeof fir);
for (int i=0;i<n;i++)
{
int e=e_max++;
scanf("%d %d %d",u+e,v+e,cap+e);
nex[e]=fir[u[e]];fir[u[e]]=e;rev[e]=e+1;
e=e_max++;
u[e]=v[e-1];v[e]=u[e-1];cap[e]=0;
nex[e]=fir[u[e]];fir[u[e]]=e;rev[e]=e-1;
}//建图 int s=1,t=m,total_flow=0;
memset(flow,0,sizeof flow); for (;;)
{
int f,r;
memset(d,0,sizeof d);
d[s]=INF;
q[f=r=0]=s;
while (f<=r)
{
int x=q[f++];
for (int e=fir[x];~e;e=nex[e])
{
if (!d[v[e]] && cap[e]>flow[e])
{
d[v[e]]=min(d[u[e]],cap[e]-flow[e]);
p[v[e]]=e;
q[++r]=v[e];
}
}
}//BFS找增广路 if (d[t]==0) break;//流量为0,无残量 //更新路径上的流量
for (int e=p[t];;e=p[u[e]])
{
flow[e]+=d[t];
flow[rev[e]]-=d[t];
if (u[e]==s) break;
} total_flow+=d[t];
} printf("%d\n",total_flow);
} return 0;
}
POJ 1273 Drainage Ditches (网络最大流)的更多相关文章
- poj 1273 Drainage Ditches(最大流)
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- poj 1273 Drainage Ditches(最大流,E-K算法)
一.Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clove ...
- poj 1273 Drainage Ditches【最大流入门】
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 63924 Accepted: 2467 ...
- poj 1273 Drainage Ditches 网络流最大流基础
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59176 Accepted: 2272 ...
- POJ 1273 Drainage Ditches【最大流】
题意:给出起点是一个池塘,M条沟渠,给出这M条沟渠的最大流量,再给出终点是一条河流,问从起点通过沟渠最多能够排多少水到河流里面去 看的紫书的最大流,还不是很理解,照着敲了一遍 #include< ...
- poj 1273 Drainage Ditches (网络流 最大流)
网络流模板题. ============================================================================================ ...
- POJ 1273 Drainage Ditches【最大流模版】
题意:现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条有向水渠,给出这n条水渠所连接的点和所能流过的最大流量,求从源点到汇点能流过的最大流量 Dinic #include<iost ...
- poj 1273 && hdu 1532 Drainage Ditches (网络最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53640 Accepted: 2044 ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
随机推荐
- 简单的图形学(三)——光源
参考自:用JavaScript玩转计算机图形学(二)基本光源 - Milo Yip - 博客园,主要讲述三种最基本的光源--平行光.点光源.聚光灯,其实就是三种数学模型. 代码的调整 先前的代码中,颜 ...
- 【转】PNG文件结构
本文转自:http://blog.csdn.net/bisword/article/details/2777121 前言 我们都知道,在进行J2ME的手机应用程序开发的时候,在图片的使用上,我们可以 ...
- sqlite遇到database is locked问题的完美解决
这两天在项目中用大强度大频率的方法测试时遇到sqlite报database is locked的问题,分析下来原因是sqlite对数据库做修改操作时会做(文件)锁使得其它进程同一时间使用时会报该错误( ...
- SharePoint自动化系列——Error features自动deactivate
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ SharePoint Content Deployment prerequisite——Error ...
- 常见Java工具——jps
简介 最常用的一个. 与Linux中的查看Java进程命令功能相同: ps -ef | grep java jps与这个命令的区别在于,jps仅仅过滤出Java本身的进程以及运行的引导类,就是引导ma ...
- 【WPF】MVVM动态修改Bingding的另一种思路——用Style样式
问题场景: 界面上有个ListBox控件,它的内容Item绑定了一个列表,即 ItemsSource =”{Binding StudentList}”.这个StudentList列表在该界面View对 ...
- 【C#/WPF】GridSplitter 分割布局,拖拽控件分隔栏以改变控件尺寸
需求:界面由多部分控件组成,想要拖拽控件之间的分隔栏以改变尺寸. MainWindow.xaml: <Grid> <Grid.ColumnDefinitions> <Co ...
- 【WPF】MVVM前台绑定一组RadioButton按钮
需求:制作一组RadioButton,像下面这样的效果: [MVVM]要显示一组RadioButton按钮,想法是Controller层联网获取到数据后,将数据进行处理,然后加到一个Observabl ...
- 【WPF】用代码给集合(Collection)容器动态添加子元素(Item)
需求:如何向 TabControl 中添加选项卡项. 问题:做的TabControl分页栏想要通过代码来控制添加的子元素.同理可以将解决思路拓展到用于其他的集合控件添加子元素的问题. 在布局文件She ...
- MyBatis批量操作报错:Parameter 'xxxList' not found. Available parameters are [list]
问题背景: 在Dao中使用MyBatis进行查询操作,参数是传的一个List:studentNameList,但是在执行查询的时候报错,具体日志如下: com.chenzhou.base.mybati ...