TZOJ 4085 Drainage Ditches(最大流)
描述
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.
输入
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.
输出
For each case, output a single integer, the maximum rate at which water may emptied from the pond.
样例输入
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
样例输出
50
题意
M条边N个点,M行每行u,v,w,代表从u到v的最大流量w
题解
直接建图跑最大流,入门题
代码
#include<bits/stdc++.h>
using namespace std; const int N=,M=;
int c[N][N],pre[N],n,m,S,T;
bool bfs()
{
int vis[N]={};
memset(pre,,sizeof pre);
queue<int>q;
q.push(S);
while(!q.empty())
{
int u=q.front();q.pop();
for(int v=;v<=n;v++)
{
if(c[u][v]>&&!vis[v])
{
pre[v]=u;
if(v==n)return true;
vis[v]=;
q.push(v);
}
}
}
return false;
}
int maxflow()
{
int flow=;
while(bfs())
{
int d=1e9;
for(int i=T;i!=;i=pre[i])d=min(d,c[pre[i]][i]);
for(int i=T;i!=;i=pre[i])
c[pre[i]][i]-=d,
c[i][pre[i]]+=d;
flow+=d;
}
return flow;
}
int main()
{
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(c,,sizeof c);
for(int i=,u,v,w;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
c[u][v]+=w;
}
S=,T=n;
printf("%d\n",maxflow());
}
return ;
}
TZOJ 4085 Drainage Ditches(最大流)的更多相关文章
- Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )
题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...
- poj 1273 Drainage Ditches 最大流入门题
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
- POJ 1273 || HDU 1532 Drainage Ditches (最大流模型)
Drainage DitchesHal Burch Time Limit 1000 ms Memory Limit 65536 kb description Every time it rains o ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- HDU1532 Drainage Ditches —— 最大流(sap算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/ ...
- poj-1273 Drainage Ditches(最大流基础题)
题目链接: Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67475 Accepted ...
- hdu 1532 Drainage Ditches(最大流)
Drainage Dit ...
- POJ-1273 Drainage Ditches 最大流Dinic
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65146 Accepted: 25112 De ...
- POJ1273:Drainage Ditches(最大流入门 EK,dinic算法)
http://poj.org/problem?id=1273 Description Every time it rains on Farmer John's fields, a pond forms ...
随机推荐
- du 统计文件夹大小
du -h --max-depth=1 |grep [TG] |sort #查找上G和T的目录并排序 du -sh #统计当前目录的大小,以直观方式展现 du -h --max-depth= ...
- 在windows、linux中开启nginx的Gzip压缩大大提高页面、图片加载速度<转>
为了降低tomcat服务的压力,把页面上的图片采用windows版的nginx进行加载,由于有些图片比较大,加载特别的慢,所以在nginx中打开了gzip的压缩功能.加载图片的速度快了很多. 通过站长 ...
- 爬虫--Scrapy-CrawlSpider&基于CrawlSpide的分布式爬虫
CrawlSpider 提问:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话,有几种实现方法? 方法一:基于Scrapy框架中的Spider的递归爬取进行实现(Request模块递归回调par ...
- DotNet菜鸟入门之无限极分类(一)设计篇
写这个教程的原因,是因为,无限极分类,在许多项目中,都用得到.而对于新手来说,不是很好理解,同时,操作上也有一些误区或者不当之处.所以我就斗胆,抛砖引玉一下,已一个常见的后台左侧频道树为例子,讲解一下 ...
- Redis-stat 的安装与使用
一.ruby源码安装 下载最新版的 Ruby 压缩文件.请点击这里下载. 下载 Ruby 之后,解压到新创建的目录下: $ tar -xvzf ruby-2.2.3.tgz $ cd ruby-2.2 ...
- 搭建分布式Hadoop的填坑纪录
1 每个节点ssh免密连接本机 cd ~/.ssh/ # 若没有该目录,请先执行一次ssh localhost ssh-keygen -t rsa # 会有提示,都按回车就可以 cat id_rsa. ...
- split()方法解析
split()方法用于将字符串分割为字符串数组. 废话不多说,直接贴代码: var str="How are you doing today?" console.log(str.s ...
- GIS案例学习笔记-水文分析河网提取地理建模
GIS案例学习笔记-水文分析河网提取地理建模 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:针对数字高程模型,通过水文分析,提取河网 操作时间:25分钟 数据 ...
- mysql 数据库必备命令操作,入门练习一下
mysql 数据库必备命令操作 show databases: 查看所有的数据库: create database jfedu: 创建名为jfedu数据库: use nihao: 进入jfedu数据库 ...
- Mybatis之mapper.xml配置文件中的#{}和${}
#{}表示一个占位符号,通过#{}可以实现preparedStatement向占位符中设置值,自动进行java类型和jdbc类型转换.#{}可以有效防止sql注入. #{}可以接收简单类型值或pojo ...