Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 51   Accepted Submission(s) : 33
Problem 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
USACO 93
KE 算法
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 1100
#define L 31
#define INF 1000000009
#define eps 0.00000001
/*
最大流问题
*/
int g[MAXN][MAXN], path[MAXN], flow[MAXN], start, End, n, m;
int bfs()
{
queue<int> q;
q.push(start);
memset(path, -, sizeof(path));
path[start] = ;
flow[start] = INF;
while (!q.empty())
{
int tmp = q.front();
q.pop();
if (tmp == End) break;
for (int i = ; i <= n; i++)
{
if (i != start&&g[tmp][i] && path[i] == -)
{
flow[i] = min(g[tmp][i], flow[tmp]);
path[i] = tmp;
q.push(i);
}
}
}
if (path[End] == -) return -;
return flow[End];
}
int EK()
{
int max_flow = , now, step;
while ((step = bfs())!= -)
{
max_flow += step;
now = End;
while (now != start)
{
int pre = path[now];
g[pre][now] -= step;
g[now][pre] += step;
now = pre;
}
}
return max_flow;
}
int main()
{
while (scanf("%d%d", &m, &n) != EOF)
{
memset(g, , sizeof(g));
int f, t, d;
for (int i = ; i < m; i++)
{
scanf("%d%d%d", &f, &t, &d);
g[f][t] += d;
}
start = , End = n;
printf("%d\n", EK());
}
}

网络流入门 Drainage Ditches的更多相关文章

  1. USACO93网络流入门Drainage Ditches 排水渠(DCOJ 5130)

    题目描述 (传送门:http://poj.org/problem?id=1273翻译 by sxy(AFO的蒟蒻)) 每次约翰的农场下雨,Bessie的水池里的四叶草就会被弄破.这就意味着,这些四叶草 ...

  2. 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches

    Drainage Ditches 题目抽象:给你m条边u,v,c.   n个定点,源点1,汇点n.求最大流.  最好的入门题,各种算法都可以拿来练习 (1):  一般增广路算法  ford() #in ...

  3. nyoj_323:Drainage Ditches(网络流入门)

    题目链接 网络流入门@_@,此处本人用的刘汝佳的Dinic模板 #include<bits/stdc++.h> using namespace std; const int INF = 0 ...

  4. HDU-1532 Drainage Ditches,人生第一道网络流!

    Drainage Ditches 自己拉的专题里面没有这题,网上找博客学习网络流的时候看到闯亮学长的博客然后看到这个网络流入门题!随手一敲WA了几发看讨论区才发现坑点! 本题采用的是Edmonds-K ...

  5. POJ 1273 Drainage Ditches(网络流,最大流)

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

  6. 【网络流】POJ1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 78671   Accepted: 3068 ...

  7. POJ1273 Drainage Ditches (网络流)

                                                             Drainage Ditches Time Limit: 1000MS   Memor ...

  8. HDU 1532 Drainage Ditches (网络流)

    A - Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  9. POJ 1273 Drainage Ditches (网络流Dinic模板)

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

随机推荐

  1. ::before和::after伪元素的使用

    :before和:after伪元素在CSS中可以被用来添加元素.加小标.清浮动等. 基本用法: p::before {} p::after {} 1.string <style type=&qu ...

  2. Android 显示意图和隐式意图的区别

    意图在android的应用开发中是很重要的,明白了意图的作用和使用后,对开发会有很大帮助.如果没有把意图搞懂,以后开发应用会感觉缺些什么.        意图的作用:        1.激活组件   ...

  3. 315 Count of Smaller Numbers After Self 计算右侧小于当前元素的个数

    给定一个整型数组 nums,按要求返回一个新的 counts 数组.数组 counts 有该性质: counts[i] 的值是  nums[i] 右侧小于nums[i] 的元素的数量.例子:给定 nu ...

  4. Kafka的3节点集群详细启动步骤(Zookeeper是外装)

    首先,声明,kafka集群是搭建在hadoop1.hadoop2和hadoop3机器上. kafka_2.10-0.8.1.1.tgz的1或3节点集群的下载.安装和配置(图文详细教程)绝对干货 如下分 ...

  5. JAVA中list,set,map与数组之间的转换详解

    package test; import java.util.*; /** * Created by ming */ public class Test { public static void ma ...

  6. java学习笔记_网络

    客户端 import java.io.*; import java.net.*; public class DailyAdviceClient { public void go() { try { S ...

  7. 最容易理解的CSS的position教程——十步图解CSS的position

    CSS的positon,我想做为一个Web制作者来说都有碰到过,但至于对其是否真正的了解呢?那我就不也说了,至少我自己并不非常的了解其内核的运行.今天在Learn CSS Positioning in ...

  8. 一、CSS的基础样式

    CSS的基础样式 border 边框 复合写法 border:border-width  border-style border-color: border-width:边框宽度 top right ...

  9. 常用MySQL语句整合

    常用MySQL语句整合 1. MySQL服务的配置和使用 修改MySQL管理员的口令:mysqladmin –u root password 密码字符串 如:mysqldmin –u root pas ...

  10. 011--c数组--排序--组成最大数

    数组--排序--组成最大数   组成最大数   任意输入一个自然数,输出该自然数的各位数字组成的最大数.例如,输入 1593 ,则输出为 9531 . 输入: 自然数 n 输出: 各位数字组成的最大数 ...