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. php排序函数测试

    1.sort,asort,arsort函数 十万个数的数组排序,用了0.17秒 $starttime=explode(' ',microtime());;for ($i=0; $i <10000 ...

  2. Akka源码分析-Actor&ActorContext&ActorRef&ActorCell

    分析源码的过程中我们发现,Akka出现了Actor.ActorRef.ActorCell.ActorContext等几个相似的概念,它们之间究竟有什么区别和联系呢? /** * Actor base ...

  3. 数据库部署到linux服务器,供本地访问。

    1.  将本地的sql文件上传至服务器 scp /Users/fangke/Documents/article.sql root@IP:/usr/local 2. 登陆服务器的mysql 3. 创建数 ...

  4. Python学习(一)-在VS上搭建开发环境

    1.到官网下载最新Python 注意:虽然目前大部分应用是Python2写的,但Python3必定会成为以后的主流 不管选择学习哪个,了解pyhton2和pyhton3的差异是必须的 2.安装Pyth ...

  5. Java—解压zip文件

    import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import ja ...

  6. csf 课件转化为wmv正常格式

    1. 下载csf文件到本地:如下图 2.从下面百度网盘下载到本地: https://pan.baidu.com/s/1BBbgq  n85a 3.安装并出现下面图标,点击打开 4. 运行如下图 5.  ...

  7. python 之 sqlite3

    # -*- coding: utf-8 -*- ''' 创建数据库日志,三列为时间 身份证号和备注名''' import os import sys import sqlite3 import dat ...

  8. Lazarus Reading XML- with TXMLDocument and TXPathVariable

    也就是使用XPath的方式,具体语法规则查看http://www.w3school.com.cn/xpath/xpath_syntax.asp,说明得相当详细.这里列举例子是说明在Lazarus/FP ...

  9. Lazarus Reading XML- with TXMLDocument and TDOMNode

    这里读取'HistoryPath' ,'TracePath' 元素下的‘value’属性使用的是 var xmlCfg: TXMLDocument; .... function ReadXMLCFG: ...

  10. 微信小程序video

    1.video是原生组件原生组件的层级是最高的,想要覆盖在video上,只能用cover-view 和 cover-image 组件,这2个可以无限嵌套.适用场景:给视频加标题: 2.检测video播 ...