Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 69355   Accepted: 26873

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

 
题意:现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给出这n条水渠所连接的池塘和所能流过的水量,求水渠中所能流过的水的最大容量.一道基础的最大流题目。
分析:嗯,这里有判重,两个点之间有多条边。不看模板已经可以做了。
#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的更多相关文章

  1. UVA 820 --- POJ 1273 最大流

    找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...

  2. poj 1273 最大流

    题目链接:http://poj.org/problem?id=1273 a.EK算法:(Edmond-Karp): 用BFS不断找增广路径,当找不到增广路径时当前流量即为最大流. b.dinic算法: ...

  3. [转载 ]POJ 1273 最大流模板

    转载 百度文库花了5分下的 不过确实是自己需要的东西经典的最大流题POJ1273 ——其他练习题 POJ3436 . 题意描述: 现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给 ...

  4. poj 1273最大流dinic算法模板

    #include<stdio.h> #include<string.h> #define N 300 #define inf 0x7fffffff #include<qu ...

  5. poj 1273 最大流入门

    明天再拍一遍 #include <iostream> #include <queue> using namespace std; ; const int INF = 0x7FF ...

  6. POJ 1273 Drainage Ditches(网络流dinic算法模板)

    POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...

  7. poj 3281 最大流+建图

    很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很 ...

  8. 最大流EK和Dinic算法

    最大流EK和Dinic算法 EK算法 最朴素的求最大流的算法. 做法:不停的寻找增广路,直到找不到为止 代码如下: @Frosero #include <cstdio> #include ...

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

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

随机推荐

  1. .NET: WPF Binding对数据的校验和转换以及多路Binding

    一.校验 一般需要对target上的值进行校验. xaml: <Window x:Class="WpfApplication1.MainWindow" xmlns=" ...

  2. vs2003打包

    怎样将.Net程序部署到没有安装.Net Framwork的机器上? 部署在.Net 平台下开发的应用程序,需要安装安装对应版本的.Net Framwork,而Vsual Studio 2003并没有 ...

  3. React-Native坑1:Invariant Violation:Application 项目名 has not been registered.

    React-Native坑1:Invariant Violation:Application 项目名 has not been registered. 字数347 阅读1421 评论3 喜欢7 前言 ...

  4. register_shutdown_function

    脚本时常死掉,而且并不总是那么好看. 我们可不想给用户显示一个致命错误,又或者一个空白页(在display_errors设为off的情况下) . PHP中有一个叫做  register_shutdow ...

  5. 弱类型变量原理探究(转载 http://www.csdn.net/article/2014-09-15/2821685-exploring-of-the-php)

    N首页> 云计算 [问底]王帅:深入PHP内核(一)——弱类型变量原理探究 发表于2014-09-19 09:00| 13055次阅读| 来源CSDN| 36 条评论| 作者王帅 问底PHP王帅 ...

  6. logging

    #coding=utf8 import sys, logging   logging.basicConfig(level=logging.INFO,                     forma ...

  7. Scrum站立会议----11月4日

    小组名称:nice! 组长:李权 成员:于淼  刘芳芳韩媛媛 宫丽君 时间:2016.11.4    12:00--12:30 地点:传媒西楼220室 代码地址:Https:  https://git ...

  8. java web sql注入测试(4)--如何防止该类缺陷发生

    检查用户输入的合法性,确信输入的内容只包含合法的数据,数据检查应当在客户端和服务器端都执行之所以要执行服务器端验证,是为了弥补客户端验证机制脆弱的安全性.在客户端,攻击者完全有可能获得网页的源代码,修 ...

  9. Windows7(x64)下Oracle10g安装

    安装环境:Windows7 (64位版本) + Oracle10g 问题描述1:无法启动安装程序,程序提示“程序异常终止.发生内部错误....” 解决过程:按网上说法加6.1版本参数,按xp兼容模式启 ...

  10. HttpHandler和ashx要实现IRequiresSessionState接口才能访问Session信息(转载)

    通常我们经常,通过session判定用户是否登录.还有一些临时的.重要的数据也尝尝存放在Session中. 在页面我们很容易的得到Session的值,但在类中就会遇到一些问题.也知道通过下面的方法得到 ...