POJ 1273 Drainage Ditches
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 67387 | Accepted: 26035 |
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
_________________________________________________________________
这好像是道网络流模板题
但为何我做得一点模板样都没有
/*POJ1273 Drainage Ditches*/
//网络流模板题
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
const int INF=1000000;
struct Ed{
int f,t;
int cap,flow;
Ed(int u,int v,int c,int f):f(u),t(v),cap(c),flow(f){}
};
int s,n,m;//起点,结点数,终点
vector<Ed> e;//边
vector<int> G[2000];//邻接表,存储边序号
int a[600];//残量
int p[600];//保存线路用以回溯
//
void clear1(int n){//初始化
for(int i=0;i<=n;i++) G[i].clear();
e.clear();
}
void add_edge(int from,int to,int cap){//添加边,正反向边相邻存储
e.push_back(Ed(from,to,cap,0));
e.push_back(Ed(to,from,0,0));
int si=e.size();
G[from].push_back(si-2);
G[to].push_back(si-1);//相邻两条边分别加入邻接表
return;
}
int fl(){
int res=0,i;
for(;;){//BFS
memset(a,0,sizeof(a));
queue<int>q;
q.push(s);
a[s]=INF;
while(!q.empty()){
int x=q.front();//本轮出发点
q.pop();
for(i=0;i<G[x].size();i++){
Ed& edge=e[G[x][i]];
if(!a[edge.t] && edge.cap>edge.flow){//之前未到达,且结点有剩余流量
a[edge.t]=min(a[x],edge.cap-edge.flow);
p[edge.t]=G[x][i];
q.push(edge.t);
} <pre name="code" class="cpp"> if(a[m])break;//找到增广路,退出
}if(!a[m])break;//无增广路,结束 for(int u=m;u!=s;u=e[p[u]].f){e[p[u]].flow+=a[m];// e[p[u]^1].flow-=a[m];}res+=a[m];}return res;}int main(){s=1;while(scanf("%d%d",&n,&m)!=EOF){clear1(n);int i,j,u,v,c;for(i=1;i<=n;i++){scanf("%d%d%d",&u,&v,&c);add_edge(u,v,c);}printf("%d\n",fl());}return
0;}
POJ 1273 Drainage Ditches的更多相关文章
- 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 最大流入门题
题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...
- 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题解——S.B.S.
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 67823 Accepted: 2620 ...
- 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 ...
- 网络流最经典的入门题 各种网络流算法都能AC。 poj 1273 Drainage Ditches
Drainage Ditches 题目抽象:给你m条边u,v,c. n个定点,源点1,汇点n.求最大流. 最好的入门题,各种算法都可以拿来练习 (1): 一般增广路算法 ford() #in ...
随机推荐
- css 内容超过容器宽度,checkbox等控件不会随着内容延伸
<div a> <div id='内容容器'> <div>很长的内容</div><input type='checkbox'/> </ ...
- http://kb.cnblogs.com/zt/ef/
http://kb.cnblogs.com/zt/ef/ http://blog.csdn.net/mackz/article/details/8605063 http://www.telerik.c ...
- UML:类图复习-鸡生蛋,蛋生鸡
这是前一阵<高级软件工程>课堂上,老师随堂出的一道讨论题,随手贴在这里: ps: 今天是520,正好聊一些OoXx,关于爱的扯淡话题:) 题目:“鸡生蛋,蛋孵鸡”,世间万物生生不息,如何用 ...
- 迭代和递归 - leetcode 206. Reverse Linked List
Reverse Linked List,一道有趣的题目.给你一个链表,输出反向链表.因为我用的是JavaScript提交,所以链表的每个节点都是一个对象.例如1->2->3,就要得到3-& ...
- 基于DDD的.NET开发框架 - ABP领域服务
返回ABP系列 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应 ...
- promise的学习
为了解决回调地狱的问题,所以出现了promise的设计思想. promise的三种状态: pending 等待状态 resolved 完成状态 rejected 拒绝状态 promise的三种状态,只 ...
- [BZOJ2152]聪聪可可(点分治)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2152 分析:裸的点分治,对于每课树,记录t[0],t[1],t[2]表示到当前根节点距 ...
- N-gram模型
n元语法 n-gram grammar 建立在马尔可夫模型上的一种概率语法.它通过对自然语言的符号串中n个符号同时出现概率的统计数据来推断句子的结构关系.当n=2时,称为二元语法,当 ...
- Android多线程文件下载
版本信息 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion " ...
- mysql忘记密码怎么办?
mysql有时候忘记密码了怎么办?我给出案例和说明!一下就解决了! Windows下的实际操作如下 1.关闭正在运行的MySQL. 2.打开DOS窗口,转到mysql\bin目录. 3.输入mysql ...