hihocode#1369 : 网络流一·Ford-Fulkerson算法(EK)
来源:互联网 发布:正规网络兼职赚钱 编辑:程序博客网 时间:2024/05/16 07:12
题目链接
最大流模板:求一个有向图的最大流(EK算法)
代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<stack>#include<bitset>#include<cstdlib>#include<sstream>#include<cctype>#include<cmath>#include<set>#include<list>#include<deque>#include<map>#include<queue>using namespace std;typedef long long ll;const double PI=acos(-1.0);const double eps=1e-6;const int INF=0x7fffffff;const int maxn=654321;int T;int n,m,s,t;int ans,flag,tot;int head[maxn],path[maxn],vis[maxn];struct Edge{ int from,to; int cap; int next;}e[maxn];void init(){ tot=0; s=1; t=n; memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); memset(path,0,sizeof(path));}void add_edge(int u,int v,int w){ e[tot].from=u; e[tot].to=v; e[tot].cap=w; e[tot].next=head[u]; head[u]=tot++;}int bfs(){ queue<int>q; q.push(s); vis[s]=1; path[s]=-1; while(!q.empty()) { int u=q.front(); q.pop(); for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; if(e[i].cap>0&&!vis[v]) { path[v]=i; vis[v]=1; if(v==t) return 1; q.push(v); } } } return 0;}int EK(){ int maxFlow=0; int flow,i; while(bfs()) { memset(vis,0,sizeof(vis)); i=path[t]; flow=INF; while(i!=-1) { flow=min(flow,e[i].cap); i=path[e[i].from]; } i=path[t]; while(i!=-1) { e[i].cap-=flow; e[i^1].cap+=flow; i=path[e[i].from]; } maxFlow+=flow; } return maxFlow;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { init(); for(int i=0;i<m;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); add_edge(a,b,c); add_edge(b,a,0); } printf("%d\n",EK()); } return 0;}
阅读全文
0 0
- hihocode#1369 : 网络流一·Ford-Fulkerson算法(EK)
- 网络流一·Ford-Fulkerson算法
- HihoCoder #1369 : 网络流一·Ford-Fulkerson算法
- hihocoder #1369 : 网络流一·Ford-Fulkerson算法
- hihocoder 1369: 网络流一·Ford-Fulkerson算法
- hihocoder#1369 : 网络流一·Ford-Fulkerson算法
- hihoCoder 题目1 : 网络流一·Ford-Fulkerson算法
- hihocoder1369 网络流一·Ford-Fulkerson算法
- 网络流--ford-fulkerson算法
- HDU 1532-Drainage Ditches(网络最大流,EK,Ford-Fulkerson,dinic3种算法套模板)
- hihoCoder 1369 网络流一·Ford-Fulkerson算法 (网络流学习#1 记录)
- hihoCoder-第115周-网络流一·Ford-Fulkerson算法
- 网络流Ford—Fulkerson算法
- 网络流问题Ford-Fulkerson算法详解
- 最大网络流的Ford-Fulkerson 算法
- 最大流 Ford Fulkerson, EK, SAP
- poj 3281 Dining 【图论-网络流-最大流-EK&Ford-Fulkerson】
- 增广路算法 Ford-Fulkerson算法 网络最大流问题
- 扩展欧几里得以及欧拉
- poj 2104 K-th Number(主席树)
- Python爬取登录后的OJ练习中的题目数据
- < 笔记 > Java SE
- win7下安装配置tomcat,java运行环境
- hihocode#1369 : 网络流一·Ford-Fulkerson算法(EK)
- dbUtils 中的各种 Handler 什么 意思
- C语言 打印九九乘法表
- Ubuntu16.04 安装WPS(亲测)
- verilog简单驱动LCD1602
- BZOJ 4016: [FJOI2014]最短路径树问题
- web 存储
- Jinjia2Template
- STM32时钟体系结构