POJ1273 Drainage Ditches (网络流)

时间:2021-02-21 10:30:01
                                                         Drainage Ditches
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 69983   Accepted: 27151

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
【分析】我直接套的树上的网络流标号法模板。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
using namespace std;
const int N=;
const int M=;
int s,t,n,m,num,k;
int customer[N][N];
int flow[N][N];
int house[M],last[M];
int pre[N],minflow[N]; void BFS() {
queue<int>q;
int p=;
memset(flow,,sizeof(flow));
minflow[]=inf;
while() {
while(!q.empty())q.pop();
for(int i=; i<N; i++)pre[i]=-;
pre[]=-;
q.push();
while(!q.empty()&&pre[t]==-) {
int v=q.front();
q.pop();
for(int i=; i<t+; i++) {
if(pre[i]==-&&(p=customer[v][i]-flow[v][i])) {
pre[i]=v;
q.push(i);
minflow[i]=min(p,minflow[v]);
}
}
}
if(pre[t]==-)break;
int j;
for(int i=pre[t],j=t; i>=; j=i,i=pre[i]) {
flow[i][j]+=minflow[t];
flow[j][i]=-flow[i][j];
}
}
for(int i=; i<t; i++)p+=flow[i][t];
printf("%d\n",p);
}
int main() {
while(~scanf("%d%d",&m,&n)) {
memset(last,,sizeof(last));
memset(customer,,sizeof(customer));
s=;
t=n;
int a,b,c;
for(int i=; i<=m; i++){
scanf("%d%d%d",&a,&b,&c);
customer[a][b]+=c;
}
BFS();
}
return ;
}

POJ1273 Drainage Ditches (网络流)的更多相关文章

  1. poj1273 Drainage Ditches Dinic最大流

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 76000   Accepted: 2953 ...

  2. 【网络流】POJ1273 Drainage Ditches

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

  3. poj1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68414   Accepted: 2648 ...

  4. POJ 1273 Drainage Ditches &lpar;网络流Dinic模板&rpar;

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

  5. POJ 1273:Drainage Ditches 网络流模板题

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63339   Accepted: 2443 ...

  6. HDU1532 Drainage Ditches 网络流EK算法

    Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...

  7. POJ-1273 Drainage Ditches 最大流Dinic

    Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...

  8. USACO 4&period;2 Drainage Ditches&lpar;网络流模板题&rpar;

    Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...

  9. NYOJ 323 Drainage Ditches 网络流 FF 练手

    Drainage Ditches 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 Every time it rains on Farmer John's fields, ...

随机推荐

  1. ncurses-devel

    :Install ncurses(ncurses-devel) and try again. 做一个简单的铺垫,ncurses是字符终端下屏幕控制的基本库.可能很多新开发的程序已经不再使用.假如要编译 ...

  2. October 2nd 2016 Week 41st Sunday

    The road to success is lined with many tempting parking spaces. 通往成功的路边充斥着许多诱人的休息区. Exhausted, I thi ...

  3. ocLazyLoad angular 按需加载

    ionic 框架 1.引用 index.html 加载 <script type="text/javascript" src="lib/oclazyload/ocL ...

  4. firs tday

    1.JVM 解析: 2.JDBC 解析: 3.Spring

  5. JS初学之-for套for遍历二维数组

    <!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...

  6. php在apache中一共有三种工作方式:CGI模式、FastCGI模式、Apache 模块DLL

    php在apache中一共有三种工作方式:CGI模式.FastCGI .FastCGI是什么? FastCGI是语言无关的.可伸缩架构的CGI开放扩展,其主要行 为是将CGI解释器进程保持在内存中并因 ...

  7. 基于TLS的反调试技术

    TLS(Thread Local Storage 线程局部存储) 一个进程中的每个线程在访问同一个线程局部存储时,访问到的都是独立的绑定于该线程的数据块.在PEB(进程环境块)中TLS存储槽共64个( ...

  8. js实现方法的链式调用

    假如这里有三个方法:person.unmerried();person.process();person.married();在jQuery中通常的写法是:person.unmerried().pro ...

  9. 栈 &amp&semi; 堆 &vert;--&gt&semi; 内存管理

    内存管理: 栈区 [stack]:由编译器自动分配并释放,一般存放函数的参数值,局部变量等 堆区 [heap]:由程序员分配和释放,如果程序员不释放,程序结束时,可能会由操作系统回收 全局区(静态区) ...

  10. ajax 跨域请求解决方案

    1.为什么出现跨域: 前端和后端同一个项目下,ajax请求的地址是localhost同一个端口是话,是不会出现跨域问题的,所以相反前端和后端分开时,ajax请求的地址或者端口不是跟后台相同时就会出现跨 ...