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. Swift语言实战晋级-第9章 游戏实战-跑酷熊猫-4 熊猫的跳和打滚

    之前我们学会了跑的动作,现在我们可以利用同样的方法来实现了跳和打滚的动画. …… class Panda : SKSpriteNode { …… //跳的纹理集合 let jumpAtlas = SK ...

  2. !!20160829——多次错误的T+0操作

  3. [原创]java WEB学习笔记83:Hibernate学习之路---双向 1-n介绍,关键点解释,代码实现,set属性介绍(inverse,cascade ,order-by )

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  4. poj: 3006

    简单题 #include <iostream> #include <stdio.h> #include <string> #include <stack> ...

  5. Missing artifact com.sun:tools:jar 1.5.0 终极解决方法

    在使用m2eclipse插件时,在pom.xml中添加struts2-core.jar包后,需要依赖java运行时的tools.jar进行依赖.但是,此时eclipse无法读取tools包,出现如下错 ...

  6. Calculation控制台

    接口 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace s ...

  7. mysql创建视图

    CREATE ALGORI`sync_user`CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER V ...

  8. inline-block去掉空白距离的方法

    一.现象描述:inline-block形式水平呈现的元素,换行显示或空格分割的情况下,元素之间会有间距,实例如下: 使用CSS将行内元素的display设置为inline-block时,也会出现间隔: ...

  9. co css规范

    CSS 编码规范 1. 文件组织 (建议试试LESS) 1.1 CSS 与 HTML CSS 一律写在 CSS 文件中,原则上不写内联样式. CSS 文件命名由小写字母.下划线(_)组成. CSS 文 ...

  10. css中的选择器

    选择器            说明    *                通用元素选择器,匹配任何元素    E                标签选择器,匹配所有使用E标签(所有HTML元素)的元 ...