HDU 3549 Flow Problem ( 最大流 -EK 算法)
来源:互联网 发布:数据分析架构 编辑:程序博客网 时间:2024/05/07 18:55
C++,G++的读取速度差距也太大了
Flow Problem
题意:n,m表示n个点m条有向带权边
问:从1-n最大流多少
裸最大流,拿来练手,挺不错的
#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>const int N = 210;#define MIN INT_MIN#define MAX INT_MAX#define LL long longusing namespace std;int max(int a,int b){if(a>b)return a; else return b;}int min(int a,int b){if(a<b)return a; else return b;}int c[100][100];int re[100];int f[100][100];int p[100],n,m;void init(){ for(int i = 0;i<=n;i++) { for(int j = 0;j<=n;j++) { c[i][j] = f[i][j] = 0; } p[i] = 0; }}void EK(int s,int t){ queue<int >q; while(q.empty()==false) q.pop(); int sum = 0; while(1) { memset(re,0,sizeof(re)); q.push(s); re[s] = MAX; p[s] = -1; while(!q.empty()) { int u = q.front(); q.pop(); for(int i = 1;i<=n;i++) { if(!re[i] && f[u][i] < c[u][i]) { q.push(i); p[i] = u; re[i] = min(re[u],c[u][i]-f[u][i]); } } } if(re[t]==0) break; for(int st = t;st!=s;st = p[st]) { f[p[st]][st] += re[t]; f[st][p[st]] -= re[t]; } sum += re[t]; } printf("%d\n",sum);}int main(){ int t,C=0,a,b,w; scanf("%d",&t); while(t--) { C++; scanf("%d%d",&n,&m); init(); for(int i = 0;i<m;i++) { scanf("%d%d%d",&a,&b,&w); c[a][b] += w; } printf("Case %d: ",C); EK(1,n); } return 0;}
0 0
- hdu 3549 Flow Problem(最大流EK算法模板)
- HDU 3549 Flow Problem ( 最大流 -EK 算法)
- HDU 3549 Flow Problem【最大流模板题,EK算法】
- hdu 3549 Flow Problem (EK 最大流)
- hdu 3549 Flow Problem 最大流入门 EK算法
- hdu3549 Flow Problem--EK算法 & 最大流
- HDU 3549 Flow Problem 最大流 最小增广路 EK算法 传说中的入门算法
- 【最大流(EK)】hdu 3549 Flow Problem
- hdu 3549 Flow Problem (最大流—EK—Dinic)
- hdu 3549 Flow Problem(最大流 EK,sap)
- HDU 3549 Flow Problem(最大流+EK邻接表||邻接矩阵||dinic算法模板比较)
- hdu 3549 EK算法 Flow Problem
- hdu 3549 Flow Problem ek算法,网络流
- hdu 3549 Flow Problem EK算法 网络流
- HDU 3549 Flow Problem 网络流 EK
- HDU3549:Flow Problem(最大流 & Ek算法 + Dinic算法)
- HDU 3549 Flow Problem(最大流裸题,EK解法)
- hdu 3545 Flow Problem 最大流模板题 EK+Dinic算法两种代码AC
- hdu4927 Series 1(组合+公式 Java大数高精度运算)
- Sequence
- 算法系列:求幂算法
- PHP 标记形式
- typedef和#define的用法与区别
- HDU 3549 Flow Problem ( 最大流 -EK 算法)
- 重构个人版机房收费系统——sqlHelper
- 用friend函数修改类的private数据
- MDN Web 技术文档 - JavaScript Strict mode
- HDU-4906 Our happy ending 状压DP
- ShellExecute实现对外部程序控制
- GIZA++实现了IBM模型1~5 IBM Model 1详解
- 用get()和put()读写二进制文件
- java——编程小技巧(三)流处理