POJ-1273 Drainage Ditches
2017-01-22 12:54
309 查看
题意:
n个河流,m个点,询问从1->m最大的流量是多少
思路:
网络流基础知识,http://www.cnblogs.com/luweiseu/archive/2012/07/14/2591573.html
去这个看吧,写的真够好。然后就是。。。板子
n个河流,m个点,询问从1->m最大的流量是多少
思路:
网络流基础知识,http://www.cnblogs.com/luweiseu/archive/2012/07/14/2591573.html
去这个看吧,写的真够好。然后就是。。。板子
#include <iostream> #include <queue> #include<cstring> #include <stdio.h> using namespace std; const int N = 205; const int INF = 0x3f3f3f3f; int n,m,mp ,path ,flow ,st,ed; queue<int> q; int bfs() { while(!q.empty()) q.pop(); memset(path,-1,sizeof(path)); path[st]=0,flow[st]=INF; q.push(st); while(!q.empty()) { int t=q.front(); q.pop(); for(int i=1;i<=m;i++) { if(i!=st&&mp[t][i]&&path[i]==-1) { flow[i]=min(flow[t],mp[t][i]); path[i]=t; q.push(i); } } } if(path[ed]==-1) return -1; return flow[ed]; } int Edmonds_Karp() { int max_flow=0,step,now,pre; while((step=bfs())!=-1) { max_flow+=step; now=ed; while(now!=st) { pre=path[now]; mp[pre][now]-=step; mp[now][pre]+=step; now=pre; } } return max_flow; } int main() { int i,u,v,cost; while(scanf("%d%d",&n,&m)!=EOF) { memset(mp,0,sizeof(mp)); for(int i=1; i<=n; i++) { scanf("%d%d%d",&u,&v,&cost); mp[u][v]+=cost; } st=1,ed=m; printf("%d\n",Edmonds_Karp()); } return 0; } /* 2 3 1 2 10 2 3 5 */
相关文章推荐
- 最大流入门 之 poj 1273
- POJ1273 Drainage Ditches(dinic)
- POJ - 1273 Drainage Ditches(最大流)
- poj1273 Drainage Ditches(最大流入门)
- poj 1273 Drainage Ditches【最大流 dinic】
- 【最大流(dinic)】poj 1273 Drainage Ditches
- poj 1273 Drainage Ditches 最大流
- POJ 1273 Drainage Ditches
- poj 1273 Drainage Ditches
- POJ 1273 Drainage Ditches POJ 1274 The Perfect Stall 最大流简单题
- poj 1273 & hdu 1532 Drainage Ditches(最大流 )EK,dinic模板
- poj 1273 Drainage Ditches 经典网络流 Dinic算法
- poj 1273 Drainage Ditches 网络流最大流入门 ford-fulkerson
- Drainage Ditches (poj 1273 && hdu 1532 网络流之Ford-Fulkerson)
- POJ 1273 Drainage Ditches—网络流,最大流模板题,Dinic算法
- POJ 1273 Drainage Ditches——最大流
- POJ1273--Drainage Ditches(最大流)
- [图论/迭代优化/动态规划]最大流问题 Edmonds-Karp算法(附POJ 1273解题)
- poj 1273 Drainage Ditches (网络流_EK_入门)
- poj 1273 最大流(三种方法)