POJ 1273:Drainage Ditches 网络流模板题
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 63339 | Accepted: 24434 |
Description
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
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
Sample Input
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
Sample Output
50
给了M个池塘,N个水渠,以及每个水渠连接的两个点和水渠的容量。(编号1为源点,编号M为汇点)。求整个网络中最大能流的水的流量。
网络流模板题。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; const int sum = 201;
const int INF = 99999999;
int cap[sum][sum],flow[sum][sum],a[sum],p[sum]; int N,M; void Edmonds_Karp()
{
int u,t,start=1,result=0;
queue <int> s;
while(s.size())s.pop(); while(1)
{
memset(a,0,sizeof(a));
memset(p,0,sizeof(p)); a[1]=INF;
s.push(1); while(s.size())
{
u=s.front();
s.pop(); for(t=1;t<=M;t++)
{
if(!a[t]&&flow[u][t]<cap[u][t])
{
s.push(t);
p[t]=u;
a[t]=min(a[u],cap[u][t]-flow[u][t]);//要和之前的那个点,逐一比较,到M时就是整个路径的最小残量
}
}
}
if(a[M]==0)
break;
result += a[M]; for(u=M;u!=1;u=p[u])
{
flow[p[u]][u] += a[M];
flow[u][p[u]] -= a[M];
}
}
cout<<result<<endl;
} int main()
{
int i,u,v,value;
while(scanf("%d%d",&N,&M)==2)
{
memset(cap,0,sizeof(cap));
memset(flow,0,sizeof(flow)); for(i=1;i<=N;i++)
{
scanf("%d%d%d",&u,&v,&value);
cap[u][v] += value;
}
Edmonds_Karp();
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1273:Drainage Ditches 网络流模板题的更多相关文章
- poj 1273 Drainage Ditches (网络流 最大流)
网络流模板题. ============================================================================================ ...
- POJ 1273 Drainage Ditches (网络流Dinic模板)
Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...
- USACO 4.2 Drainage Ditches(网络流模板题)
Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...
- POJ 1273 Drainage Ditches 网络流 FF
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 74480 Accepted: 2895 ...
- poj 1273 Drainage Ditches 网络流最大流基础
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59176 Accepted: 2272 ...
- HDU 1532 Drainage Ditches(网络流模板题)
题目大意:就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速, 本题就是让你求出最大流速,无疑要运用到求最大流了.题中m为水沟数, ...
- POJ 1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67387 Accepted: 2603 ...
- poj 1273 Drainage Ditches(最大流)
http://poj.org/problem?id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- POJ 1273 Drainage Ditches (网络最大流)
http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
随机推荐
- linux环境基于python语言docx转pdf
windows平台因借助win32com具有多种方法将word转为pdf,但linux环境不具备此环境,win32com包也将import失败,那该如何做呢? # -*- coding: utf-8 ...
- 第1节 IMPALA:2、架构介绍
impala的架构以及查询计划: impalad :从节点 对应启动一个impala-server的进程 ,主要负责各种查询计划,官方建议与所有的datanode安装在同一台机器上面 impala-s ...
- 【capstone/ropgadget】环境配置
具体环境配置可参考 https://github.com/JonathanSalwan/ROPgadget/tree/master 作者给出的安装方式 但具体配置中出现了问题,如引用时出现如下错误: ...
- 无法识别的配置节 system.webServer
Web.config文件里面加入 <configSections> <section name="system.webServer" type="Sys ...
- ACM-寻宝
题目描述:寻宝 有这么一块神奇的矩形土地,为什么神奇呢?因为上面藏有很多的宝藏.该土地由N*M个小正方形土地格子组成,每个小正方形土地格子上,如果标有“E”,则表示该格可以通过:如果标有“X”,则表示 ...
- SpringBoot#JSR303
__震惊了!,一遍一遍在业务逻辑中编写的验证条件被抽离了! 是什么: - Java Specification Requests 303 ,用于对javaBean 属性的验证. - 解决了什么问题: ...
- 深入浅出KNN算法
概述 K最近邻(kNN,k-NearestNeighbor)分类算法 所谓K最近邻,就是k个最近的邻居的意思,说的是每个样本都可以用它最接近的k个邻居来代表. kNN算法的核心思想是如果一个样本在特征 ...
- 留学Essay写作:从入门到精通
Essay作为最常见的英国大学作业形式,几乎是每个留学生都绕不过去的任务. 大部分人提到自己在英国的大学生活,都会回想起无数个“血泪交加”的夜晚,从白天到傍晚再到深夜,点灯熬油的查资料,写essay. ...
- 使用docker快速体验kali linux
环境 运行在 64位 机器 企业版的 win10 系统 下载镜像 首先搜索docker download 去官网下载docker:https://www.docker.com/products/doc ...
- 四、React创建组件、 JSX使用、绑定数据、引用图片方式、数组(列表)循环输出
接:https://www.cnblogs.com/chenxi188/p/11702799.html 用上节建好的my-app项目: my-app/ README.md node_modules/ ...