POJ 1273 Drainage Ditches【最大流】
2015-05-25 20:33
405 查看
题意:给出起点是一个池塘,M条沟渠,给出这M条沟渠的最大流量,再给出终点是一条河流,问从起点通过沟渠最多能够排多少水到河流里面去
看的紫书的最大流,还不是很理解,照着敲了一遍
View Code
寒假的cf就遇到过最大流的题目,当时不会而且还没有学
现在又遇到了,不能再这样了,先学一点点先吧-----------------------
gooooooooooooooo------------
加油====================
看的紫书的最大流,还不是很理解,照着敲了一遍
#include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set> #include<queue> #include<algorithm> using namespace std; typedef long long LL; const int INF = (1<<30)-1; const int mod=1000000007; const int maxn=10005; int n,m,M; struct Edge{ int from,to,cap,flow; Edge(int u,int v,int c,int f) :from(u),to(v),cap(c),flow(f) {} }; vector<Edge> edges;//存边 vector<int> G[maxn];//邻接表 int a[maxn];//到起点i的可改进量 int p[maxn];//最短 路树上p的入弧编号 void init(){ for(int i=0;i<n;i++) G[i].clear(); edges.clear(); } void addedges(int from,int to,int cap){ edges.push_back(Edge(from,to,cap,0)); edges.push_back(Edge(to,from,0,0));//反向弧 m=edges.size(); G[from].push_back(m-2); G[to].push_back(m-1); } int Maxflow(int s,int t){ int flow=0; for(;;){ memset(a,0,sizeof(a)); queue<int> q; q.push(s); a[s]=INF; while(!q.empty()){ int x=q.front();q.pop(); for(int i = 0;i < G[x].size(); i++){ Edge& e = edges[G[x][i]]; if(!a[e.to]&&e.cap>e.flow){ p[e.to] = G[x][i]; a[e.to] = min(a[x], e.cap-e.flow); q.push(e.to); } } if(a[t]) break; } if(!a[t]) break; for(int u = t;u !=s ;u=edges[p[u]].from){ edges[p[u]].flow+=a[t]; edges[p[u]^1].flow-=a[t]; } flow+=a[t]; } return flow; } int main(){ while(scanf("%d %d",&M,&n)!=EOF){ init(); for(int i=0;i<M;i++){ int u,v,c; scanf("%d %d %d",&u,&v,&c); u--;v--; addedges(u,v,c); } printf("%d\n",Maxflow(0,n-1)); } return 0; }
View Code
寒假的cf就遇到过最大流的题目,当时不会而且还没有学
现在又遇到了,不能再这样了,先学一点点先吧-----------------------
gooooooooooooooo------------
加油====================
相关文章推荐
- POJ - 1273 Drainage Ditches 最大流 模板题
- poj1273 Drainage Ditches(裸最大流)
- POJ-1273 Drainage Ditches(最大流)
- USACO 93, POJ 1273 排水沟(Drainage Ditches) 最大流
- poj 1273 || hdu 1532 Drainage Ditches 最大流
- POJ 1273 (基础最大流) Drainage Ditches
- POJ-1273-Drainage Ditches(裸的最大流)
- POJ1273 Drainage Ditches【最大流】【SAP】
- 最大流入门——POJ 1273
- poj1273解题报告(最大流 EK算法)
- 最大流 poj 1273 Dinic 模板
- poj 1273 Drainage Ditches(最大流)
- (最大流-简单题) poj 1273 Drainage Ditches
- POJ1273-Drainage Ditches-网络流-最大流(模板题)
- POJ 1273 网络流最大流 题解
- poj 1273 最大流入门
- poj1273(网络流最大流dinic)
- poj 1273 Drainage Ditches(最大流)
- POJ - 1273 Drainage Ditches (最大流)
- poj 1273 Drainage Ditches(最大流E-K +dinic 模板)