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. 与平台无关的类型,int8_t,uint8_t

    pecific integral type limits Specifier Common Equivalent Signing Bits Bytes Minimum Value Maximum Va ...

  2. ny36 最长公共子序列

    最长公共子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列.tip:最长公共子序列也称作最 ...

  3. AngularJS 初始化加载流程

    一.AngularJS 初始化加载流程 1.浏览器载入HTML,然后把它解析成DOM.2.浏览器载入angular.js脚本.3.AngularJS等到DOMContentLoaded事件触发.4.A ...

  4. HttpClient 教程 (五)

    第五章 HTTP客户端服务 5.1 HttpClient门面 HttpClient接口代表了最重要的HTTP请求执行的契约.它没有在请求执行处理上强加限制或特殊细节,而在连接管理,状态管理,认证和处理 ...

  5. 如何读取jar包外的properties文件和log4j.properties

    http://jrails.iteye.com/blog/1705464 ***************************************' 一般在项目中使用properties配置文件 ...

  6. 【转载】LeetCode 题目总结/分类

    引自:http://www.douban.com/note/330562764/ 注:此分类仅供大概参考,没有精雕细琢.有不同意见欢迎评论~ 利用堆栈:http://oj.leetcode.com/p ...

  7. Path类与Directory类与File类

    阅读目录 开始 Path 对路径 字符串进行操作 获得后缀 能合并路径 获取文件名 Directory和DirectoryInfo  对目录进行操作 判断目录是否存在 创建目录 删除目录 获取目录下所 ...

  8. Sqli-LABS通关笔录-5[SQL布尔型盲注]

    /* 请为原作者打个标记.出自:珍惜少年时 */   通过该关卡的学习我掌握到了 1.如何灵活的运用mysql里的MID.ASCII.length.等函数 2.布尔型盲注的认识 3.哦,对了还有.程序 ...

  9. 实战入侵(突破FCK+安全狗上传)

    PS:有点尴尬,二次上传突破FCK,免杀马儿过狗. 刚开始和超霸一起弄,TMDGB.弄到四点多,早上尼玛七点多的又去考试,虽然考试还是睡着了,但是TMDGB感觉日子好充实啊! FCK上传地址如下所示: ...

  10. 【Unity笔记】UGUI物体的Rect Transform组件(Pivot中心点,Anchor锚点)

    Pivot:自身中心点,图标是小蓝点.表示图片以哪个点来计算坐标值.默认在UI元素的几何中心点(0.5, 0,5). Anchor:锚点,图标是四个小三角形.表示该UI元素以父物体的哪个位置作为缩放参 ...