http://poj.org/problem?

id=1273

Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 55235   Accepted: 21104

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

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 (网络最大流)的更多相关文章

  1. poj 1273 Drainage Ditches(最大流)

    http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  2. poj 1273 Drainage Ditches(最大流,E-K算法)

    一.Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clove ...

  3. poj 1273 Drainage Ditches【最大流入门】

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63924   Accepted: 2467 ...

  4. poj 1273 Drainage Ditches 网络流最大流基础

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59176   Accepted: 2272 ...

  5. POJ 1273 Drainage Ditches【最大流】

    题意:给出起点是一个池塘,M条沟渠,给出这M条沟渠的最大流量,再给出终点是一条河流,问从起点通过沟渠最多能够排多少水到河流里面去 看的紫书的最大流,还不是很理解,照着敲了一遍 #include< ...

  6. poj 1273 Drainage Ditches (网络流 最大流)

    网络流模板题. ============================================================================================ ...

  7. POJ 1273 Drainage Ditches【最大流模版】

    题意:现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条有向水渠,给出这n条水渠所连接的点和所能流过的最大流量,求从源点到汇点能流过的最大流量 Dinic #include<iost ...

  8. poj 1273 && hdu 1532 Drainage Ditches (网络最大流)

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53640   Accepted: 2044 ...

  9. POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]

    题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...

随机推荐

  1. angularJS绑定数据中对标签转义的处理二 与pre标签的使用

    一.问题 默认情况下,angularJS绑定的数据为字符串文本,不会对其中包含的html标签进行转义生成格式化的文本.在实际工作时碰到接口返回的数据带有html格式时该如何处理. 二.解决办法 1.引 ...

  2. C++面向对象程序设计的一些知识点(2)

    1.C++中三种继承方式及派生类中访问控制规则 (1).C++支持的三种继承方式是public.protected.private.C++允许一个类同时以不同的方式对不同的基类加以继承. (2). 不 ...

  3. rman备份,恢复

    ackup database format 'd:\tt\%U'; rman> restore database;rman> recover database; ============= ...

  4. 浅谈C# application.DoEvent作用

    Application.DoEvents()的作用:处理所有的当前在消息队列中的Windows消息. private void button1_Click(object sender, EventAr ...

  5. 基于CSS3自定义发光radiobox单选框

    之前我们分享过一些CSS3和HTML5实现的自定义checkbox和Radiobox,比如纯CSS3美化Checkbox和Radiobox按钮,不仅外观唯美,而且Radiobox选中时还有动画效果.今 ...

  6. 三级级联查询省份名称和编码(保证名称不反复)的SQL语句

    三级级联查询省份名称和编码(保证名称不反复)的SQL语句 1.省份.地市和县级数据库表 2.SQL语句 SELECT DISTINCT t.`province_name`,t.`province_co ...

  7. LNMP环境下SendMail+OpenWebMail的详细配置

    随着网络的发展和普及,邮件服务器正在成为人们日常生活中不可缺少的部分.现在,许多企业采用 Lotus Note, Exchange 作为公司内部的邮件服务器.本文主要介绍一种基于Linux系统的邮件服 ...

  8. WHAT EXACTLY IS WASM ?!

    终于, 我入门了当初很仇视的技术.... 什么是WebAssembly? WebAssembly或WASM是一个编译器目标(由编译器生成的代码),具有二进制格式,允许我们在浏览器上执行C,C ++和R ...

  9. iOS边练边学--通讯录练习之Segue使用,控制器的数据传递

    一.什么是segue Storyboard上每一根用来界面跳转的线,都是一个UIStoryboardSegue对象(简称Segue) 二.Segue的属性 每一个segue对象,都有三个属性 < ...

  10. 《FPGA全程进阶---实战演练》第三章之PCB设计之去耦电容

    1.关于去耦电容为何需要就近摆放? 大多数资料有提到过,去耦电容就近放置,是从减小回路电感的角度去谈及摆放问题,其实还有一个原则就是去耦半径的问题,如果电容离着芯片位置较远,超过去耦半径,会起不到去耦 ...