dinic codevs 1993 草地排水题解
来源:互联网 发布:财经大数据 编辑:程序博客网 时间:2024/04/29 21:36
题目:
http://codevs.cn/problem/1993/
显然这道题是一道不用建模的裸dinic(好多网络流根本不知道是网络流啊233,可能是我太弱)
就是裸的我就不bb了,这里正向边和反向边我是用的x和x^1来存储的,代码不算长吧,关于dinic,如果需要复习或者不懂的,可以看这篇博文:
https://comzyh.com/blog/archives/568/
#include<cstdio>#include<cstring>#include<iostream>#include<queue>#define MAXN 500+10#define oo 0x7ffffffusing namespace std;struct Line{ int from,to,next,cost;}line[MAXN];int head[MAXN],tail,level[MAXN],n,m,te,mp,temp;int s=1,t,cnt;void add_line(int from,int to,int fee){ tail++; line[tail].from=from; line[tail].to=to; line[tail].cost=fee; line[tail].next=head[from]; head[from]=tail;}bool bfs(){ memset(level,0xff,sizeof(level)); queue<int>q; level[s]=0;q.push(s); while(!q.empty()){ int u=q.front();q.pop(); for(int i=head[u];i;i=line[i].next){ int v=line[i].to; if(line[i].cost>0&&level[v]==-1){ level[v]=level[u]+1; q.push(v); } } } if(level[t]==-1) return false; return true;}int dfs(int u,int maxflow){ if(u==t) return maxflow; for(int i=head[u];i;i=line[i].next){ int v=line[i].to; if(line[i].cost>0&&level[u]<level[v]){ int flow=dfs(v,min(maxflow,line[i].cost)); if(flow>0){ line[i].cost-=flow; line[i^1].cost+=flow; return flow; } } } return 0;} int main(){ scanf("%d%d",&n,&m);t=m; for(int i=1;i<=n;i++){ scanf("%d%d%d",&te,&mp,&temp); add_line(te,mp,temp); add_line(mp,te,0); } while(bfs()) cnt+=dfs(s,oo); cout<<cnt; return 0;}
阅读全文
0 0
- dinic codevs 1993 草地排水题解
- Codevs 1993 草地排水 [dinic] [最大流]
- 【codevs 1993】草地排水【Dinic裸题】
- [codevs 1993]草地排水
- Codevs 1993 草地排水
- codevs 1993草地排水
- 【codevs 1993】草地排水(最大流)
- [POJ1273]草地排水 dinic模板
- CodeVS 1993 草地排水 E-K网络流初步
- USACO Training 4.2.1 Drainage Ditches 草地排水 题解与分析<网络流DINIC算法>
- codevs 草地排水问题 网络流
- 草地排水
- 【codevs1993】草地排水,网络流入门(dinic+ispa)
- 洛谷 P2740 [USACO4.2] 草地排水Drainage Ditches [dinic算法]
- 【题解】洛谷P2740 poj1273 [USACO4.2]草地排水Drainage Ditches
- 【Drainage Ditches 草地排水】
- 【wikioi1993】草地排水
- 【wikioi1993】 草地排水
- null == obj 和 obj == null在java中推荐前者的原因
- 一道JS面试题
- USACO-Section1.2 Milking Cows
- spring学习笔记02_注解配置Bean_AOP_
- 前端开发规范:命名规范、html规范、css规范、js规范
- dinic codevs 1993 草地排水题解
- POJ 1654 Area 笔记
- C#技巧:如何自定义窗口标题栏
- Red and Black
- 详解嵌套ListView、ScrollView布局显示不全的问题
- 设计模式笔记——创建者模式
- 如何在github的浏览静态页面?
- ES6基本语法的简单用法总结(1)
- kaggle入门泰坦尼克之灾内容总结