POJ 1273 Drainage Ditches题解——S.B.S.
Drainage Ditches
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 67823 | Accepted: 26209 |
Description
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
Output
Sample Input
- 5 4
- 1 2 40
- 1 4 20
- 2 4 20
- 2 3 30
- 3 4 10
Sample Output
- 50
Source
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<algorithm>
- #include<cassert>
- #include<climits>
- #define maxn 210
- using namespace std;
- void find();
- void flow();
- void update();
- struct Edge
- {
- int c;
- int f;
- }edge[maxn][maxn];
- int n,m;
- int s,t;
- int residual[maxn][maxn];
- int que[maxn*maxn],head,tail;
- int pre[maxn];
- bool vis[maxn];
- int max_flow,min_flow;
- void find()
- {
- int i,cu;
- memset(vis,false,sizeof(vis));
- memset(residual,,sizeof(residual));
- memset(pre,,sizeof(pre));
- head=;que[head]=s;pre[s]=s;vis[s]=true;tail=;
- while(head<tail&&pre[t]==)
- {
- cu=que[head];
- for(i=;i<=n;i++)
- {
- if(vis[i]==false)
- {
- if(edge[cu][i].c-edge[cu][i].f>)
- {
- residual[cu][i]=edge[cu][i].c-edge[cu][i].f;
- pre[i]=cu;que[tail++]=i;vis[i]=true;
- }
- else if(edge[i][cu].f>)
- {
- residual[cu][i]=edge[i][cu].f;
- pre[i]=cu;que[tail++]=i;vis[i]=true;
- }
- }
- }
- head++;
- }
- }
- void flow()
- {
- int i=t,j;
- if(pre[i]==)
- {
- min_flow=;return;
- }
- j=0x7fffffff;
- while(i!=s)
- {
- if(residual[pre[i]][i]<j) j=residual[pre[i]][i];
- i=pre[i];
- }
- min_flow=j;
- }
- void update()
- {
- int i=t;
- if(pre[i]==) return;
- while(i!=s)
- {
- if(edge[pre[i]][i].c-edge[pre[i]][i].f>)
- edge[pre[i]][i].f+=min_flow;
- else if(edge[i][pre[i]].f>)
- edge[pre[i]][i].f+=min_flow;
- i=pre[i];
- }
- }
- void solve()
- {
- s=;t=n;
- max_flow=;
- while(true)
- {
- find();flow();
- max_flow+=min_flow;
- if(min_flow>) update();
- else return;
- }
- }
- int main()
- {
- std::ios::sync_with_stdio(false);
- int i,u,v,c;
- while(scanf("%d %d",&m,&n)!=EOF)
- {
- memset(edge,,sizeof(edge));
- for(i=;i<m;i++)
- {
- scanf("%d %d %d",&u,&v,&c);
- edge[u][v].c+=c;
- }
- solve();
- printf("%d\n",max_flow);
- }
- return ;
- }
POJ 1273 Drainage Ditches题解——S.B.S.的更多相关文章
- 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 ...
- POJ 1273 - Drainage Ditches - [最大流模板题] - [EK算法模板][Dinic算法模板 - 邻接表型]
题目链接:http://poj.org/problem?id=1273 Time Limit: 1000MS Memory Limit: 10000K Description Every time i ...
- 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 Drainage Ditches(最大流,E-K算法)
一.Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clove ...
- POJ 1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67387 Accepted: 2603 ...
- POJ 1273 Drainage Ditches -dinic
dinic版本 感觉dinic算法好帅,比Edmonds-Karp算法不知高到哪里去了 Description Every time it rains on Farmer John's fields, ...
- Poj 1273 Drainage Ditches(最大流 Edmonds-Karp )
题目链接:poj1273 Drainage Ditches 呜呜,今天自学网络流,看了EK算法,学的晕晕的,留个简单模板题来作纪念... #include<cstdio> #include ...
- POJ 1273 Drainage Ditches(网络流dinic算法模板)
POJ 1273给出M条边,N个点,求源点1到汇点N的最大流量. 本文主要就是附上dinic的模板,供以后参考. #include <iostream> #include <stdi ...
随机推荐
- Z.ExtensionMethods 一个强大的开源扩展库
今天有意的在博客园里面搜索了一下 Z.ExtensionMethods 这个扩展类库,确发现只搜到跟这个真正相关的才两篇博文而已,我都点进去看了一下,也都只是提到而已,没有专门介绍,才引起我写这篇文档 ...
- C# DataGridView中指定的单元格不能编辑
注意:DataGridView控件是从.NET Framework 2.0版本开始追加的. ReadOnly属性的使用 DataGridView内所有的单元格不能编辑 当DataGridView.Re ...
- mybatis报错invalid types () or values ()解决方法
原因: Pojo类User没提供无参数构造方法, 加上该构造方法后,问题解决 ### Cause: org.apache.ibatis.reflection.ReflectionException ...
- Mac上编译C++报错
今天在使用Mac编译C++文件时,提示以下错误. Undefined symbols for architecture x86_64: "std::__1::__vector_base_co ...
- karma与webpack结合
一.必备插件 1.babel:es6的语法支持 2.karma:测试框架 3.jasmine:断言框架 4.webpack:打包工具 5.karma-webpack:karma调用webpack打包接 ...
- Egret白鹭H5小游戏开发入门(二)
前言: 昨天的文章中简单的介绍了Egret白鹭引擎从安装到基本的使用配置等问题,今天着重介绍H5小游戏开发的起步阶段,如Wing面板的使用,素材的处理,类的说明,开始布局等等. 整体概况: 根据上一篇 ...
- 完美 全兼容 解决 文字两端对齐 justify 中文姓名对齐
text-align:justify; 所有浏览器都支持,text-justify之类的却只有IE支持,就不要考虑了. justify我的理解,使元素内部的子元素两端对齐,子元素当然只能是inline ...
- 那些过目不忘的H5页面
原文链接:http://isux.tencent.com/great-mobile-h5-pages.html 从引爆朋友圈的H5小游戏<围住神经猫>,到颠覆传统广告的大众点评H5专题页& ...
- 详解JavaScript中的this
JavaScript中的this总是让人迷惑,应该是js众所周知的坑之一. 个人也觉得js中的this不是一个好的设计,由于this晚绑定的特性,它可以是全局对象,当前对象,或者…有人甚至因为坑大而不 ...
- iOS GCD的 一次性执行、定时器、迭代、队列组