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 ...
随机推荐
- 我要重新开始学习C++了!
C++实在是博大精深!之前总不想读厚厚的C++ Primer. 然而,现在的水平真的只是初学者!只是因为写的代码太简单,所以没有用到一些特性.可以说还是门外汉! 写笔记!
- spring获取配制文件的参数
项目中需要获取一些万年不变的参数,比如单点登录的域名 怎么从多个文件配置中获取呢,原来spring早已经提供了类PropertyPlaceholderConfigurer <?xml versi ...
- Oracle 学习总结 - 问题诊断
搜集常用诊断sql https://blog.csdn.net/yangshangwei/article/details/52449489 lock相关: 1. 查看lock, 打开两个事物,事物1更 ...
- Android app 性能优化的思考--性能卡顿不好的原因在哪?
说到 Android 系统手机,大部分人的印象是用了一段时间就变得有点卡顿,有些程序在运行期间莫名其妙的出现崩溃,打开系统文件夹一看,发现多了很多文件,然后用手机管家 APP 不断地进行清理优化 ,才 ...
- 20.struts2的数据填充和类型转换.md
目录 1. struts2的自动填充 2. struts2的对象填充 3. struts2的类型转换器 3.1 类继承关系 3.2 局部转换器 3.3 全局转换器 3.4 注意 1. struts2的 ...
- HttpWatch Professional Edition 7.2.13下载含( license.lic )
下载地址: http://download.httpwatch.com/httpwatchpro.exe httpwatch.lic # program. # # You ca ...
- C#中的 new Random()
在C#中,产生随机数常用大方法是 new Random().Next(1,10)等方法. 但是仔细发现会有个问题: 看代码: ; i < ;i++ ) { Console.WriteLine(, ...
- Applese走方格-dfs
链接:https://ac.nowcoder.com/acm/contest/330/B来源:牛客网 题目描述 精通程序设计的 Applese 又写了一个游戏. 在这个游戏中,它位于一个 n 行 m ...
- yii 定义场景
定义场景可以限制对字段的增删改查操作
- linux下各权限的细分
PS:有时候你发现用root权限都不能修改某个文件,大部分原因是曾经用chattr命令锁定该文件了.chattr命令的作用很大,其中一些功能是由Linux内核版本来支持的,不过现在生产绝大部分跑的li ...