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. Oracle PLSQL Demo - 11.定义包头[Define PACKAGE]

    CREATE OR REPLACE PACKAGE temp_package_demo is v_demo ); PROCEDURE p_demo_1(userid NUMBER DEFAULT v_ ...

  2. HTML——动画效果:左侧固定悬浮栏(图标控制)

    效果: 默认时: 点击按钮时 html: <!DOCTYPE html> <html> <head> <title>智能家居</title> ...

  3. KMP算法匹配原理以及C++实现

    原创作品,转载请注明出处:点我 假设A表示目标字符串,A="abababaababacb",B表示匹配模式,B="ababacb" 用两个指针i和j分别表示,A ...

  4. NFS服务的端口分配

    常规的一些NFS服务设置我们已经了解了.那么对于端口问题,很多朋友并不是很清楚.这里我们就来详细介绍一下端口的分配.portmapper在NFS服务启动的时候给每一个NFS服务分配了一个动态的端口,如 ...

  5. SecureCRT连接AWS EC2云主机密码登录

    申请了亚马逊的EC2,要通过ssh 加密钥的形式登录,特别麻烦,而且感觉ssh登录AWS的云主机后好卡,这里是更改成用户名和密码的形式登录云主机,可以通过SecureCRT直接登录 1.首先通过ssh ...

  6. Ubuntu下,dpkg安装出错的修复

    参考 http://www.khattam.info/2009/08/04/solved-subprocess-pre-removal-script-returned-error-exit-statu ...

  7. 在Ubuntu中安装PHP,MySQL,Nginx和phpMyAdmin

    apt install php apt-get install php7.0 apt-get -y install php7.0-fpm 缺少 mysqli 扩展.请检查 PHP 配置. apt in ...

  8. 上手并过渡到PHP7(5)——轻量级“集合”迭代器-Generator

    轻量级“集合”迭代器-Generator泊学视频链接泊阅文档链接Generator是PHP 5.5加入的新语言特性.但是,它似乎并没有被很多PHP开发者广泛采用.因此,在我们了解PHP 7对Gener ...

  9. html精灵技术(用来显示图片的某个区域)

    .left .left_down li.a.left-down-pic{display:block;width:50px;height:50px;background:url(images/app_i ...

  10. asp.net一些面试题(转)

    基础知识 什么是面向对象 面向对象OO = 面向对象的分析OOA + 面向对象的设计OOD + 面向对象的编程OOP: 通俗的解释就是万物皆对象,把所有的事物都看作一个个可以独立的对象(单元),它们可 ...