[USACO4.2]Drainage Ditches
OJ题号:
洛谷2740、POJ1273、HDU1532
思路:
最大流模板。
1 #include<queue> 2 #include<cstdio> 3 #include<cctype> 4 #include<vector> 5 #include<cstring> 6 inline int getint() { 7 char ch; 8 while(!isdigit(ch=getchar())); 9 int x=ch^'0'; 10 while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0'); 11 return x; 12 } 13 const int E=402,V=201,inf=0x7fffffff; 14 int s,t; 15 struct Edge { 16 int from,to,remain; 17 }; 18 Edge e[E]; 19 std::vector<int> g[V]; 20 int sz=0; 21 inline void add_edge(const int u,const int v,const int w) { 22 e[sz]=(Edge){u,v,w}; 23 g[u].push_back(sz); 24 sz++; 25 } 26 int a[V],p[V]; 27 inline int Augment() { 28 memset(a,0,sizeof a); 29 a[s]=inf; 30 std::queue<int> q; 31 q.push(s); 32 while(!q.empty()&&!a[t]) { 33 int x=q.front(); 34 q.pop(); 35 for(unsigned i=0;i<g[x].size();i++) { 36 Edge &y=e[g[x][i]]; 37 if(!a[y.to]&&y.remain) { 38 p[y.to]=g[x][i]; 39 a[y.to]=std::min(a[x],y.remain); 40 q.push(y.to); 41 } 42 } 43 } 44 return a[t]; 45 } 46 inline int EdmondsKarp() { 47 int maxflow=0; 48 while(int flow=Augment()) { 49 for(int i=t;i!=s;i=e[p[i]].from) { 50 e[p[i]].remain-=flow; 51 e[p[i]^1].remain+=flow; 52 } 53 maxflow+=flow; 54 } 55 return maxflow; 56 } 57 int main() { 58 int n=getint(),m=getint(); 59 s=1,t=m; 60 for(int i=0;i<n;i++) { 61 int u=getint(),v=getint(),w=getint(); 62 add_edge(u,v,w); 63 add_edge(v,u,0); 64 } 65 printf("%d\n",EdmondsKarp()); 66 return 0; 67 }
转载于:https://www.cnblogs.com/skylee03/p/7252445.html
[USACO4.2]Drainage Ditches相关推荐
- 网络流--最大流--POJ 1273 Drainage Ditches
链接 Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clov ...
- Drainage Ditches POJ1273
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 93263 Accepted: 36174 试题链接 文章目录 Descripti ...
- USACO Section 4.2 Drainage Ditches(最大流)
最大流问题.ISAP算法.注意可能会有重边,不过我用的数据结构支持重边.距离d我直接初始化为0,也可以用BFS逆向找一次. -------------------------------------- ...
- [POJ 1273]Drainage Ditches
[问题描述] Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch ...
- poj1273 Drainage Ditches
蒟蒻的blog POJ 1273 Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Memory Limit: 10000K Total ...
- 网络流 - Drainage Ditches - HDU - 1532
Problem Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite ...
- 【网络流】解题报告:luogu P2740 [USACO4.2]草地排水Drainage Ditches(Edmonds-Karp增广路,最大流模板)
题目链接:草地排水 若一条从源点到汇点的路径上各条边的剩余容量都大于0,则称这条路径为一条增广路. Edmonds-Karp增广路的策略就是不断用bfs寻找增广路,直至网络中不在存在增广路为止. 在每 ...
- [USACO4.2]草地排水Drainage Ditches
https://www.luogu.org/problemnew/show/P2740 题解:网络流+最大流 /* *@Author: STZG *@Language: C++ */ #include ...
- [USACO4.2] 草地排水 Drainage Ditches (最大流)
题目背景 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没 ...
最新文章
- 北邮 JAVA教程 张海旸 讲义
- centos7删除符号链接_技术|在 Linux 中怎样移除(删除)符号链接
- links下c语言中for的作用是,C语言开发注意事项
- Java黑皮书课后题第7章:7.2(倒置输入的数)编写程序,读取10个整数,然后按照和读入顺序相反的顺序将它们显示出来
- DataList之数据操作
- mysql分库一致性_分库分表带来的完整性和一致性问题
- Asp.net中的时区
- 阿里云服务安装与卸载rabbitmq
- 小新air14学计算机,小新Air14对比小新Pro13哪个更香,盘点办公学习的
- cu.html 光猫 管理密码,中兴ZXHN F607联通光猫管理员账号密码获取方法
- (附源码)Springboot宠物医院管理系统 毕业设计 180923
- 英文密码特殊字符大全
- 施柏阁保时捷设计酒店全球陆续开设15家酒店;汉庭新品旗舰店在武汉街道口商圈亮相;开元酒店用国潮赋能中高端品牌 | 全球旅报...
- 未来计算机作文600字,未来的电脑作文600字(精选3篇)
- 微信小程序微信授权登录,使用getPhoneNumber()部分手机无法获取动态令牌code(Taro)
- 阿里云 Linux 3 安装mysql 亲测有效
- 只要五分钟,让你成功接入Twitter的第三方登录
- 2020-2021年度第2学期课程回顾总结
- UVM:解决phase的执行顺序
- Android架构组件Room功能详解,面试必问
热门文章
- 扩容是元素还是数组_348,数据结构1,数组
- [软件推荐]使用OneNote来构建你自己的知识库(OFFICE2010)
- idea xml文件去掉背景黄色
- StringUtils.isBlank()检验String 类型的变量是否为空
- JAVA中String字符串比较equals()和equalsIgnoreCase()的区别
- iOS 远程通知(Remote Notification)和本地通知(Local Notification)
- JQuery 动画卷页 -- 返回顶部 动画特效(兼容Chrome)
- 组件对象模型:COM
- 05 Python - Python运行
- 聊几个与赚钱相关的小事情