poj 1459 最大流问题
来源:互联网 发布:黄金分析软件 编辑:程序博客网 时间:2024/05/17 06:36
详细见1273其分析:http://blog.csdn.net/challenchenzhipeng/article/details/7686648
刚开始,MAX=101,数组大小为101,应该可以了,题目说 0 <= n <= 100 (nodes),提交后出现Runtime Error,so将MAX=102,AC了~~
#include <iostream>#include <stdio.h>#include <queue>#include <string>using namespace std;const int INF=0x7fffffff;const int MAX=102; int n,np,nc,m,s,t;//a[i]存储的是源点s到节点i的路径上的最小残留量,因为a[i]总是整数.于是可用它来替代标记数组int cap[MAX][MAX],flow[MAX][MAX]; int EKarp() { queue<int> Q; int a[MAX],u,v,f,pre[MAX]; f = 0; while(1) { Q.push(s); memset(a,0,sizeof(a)); a[s] = INF; while( !Q.empty() ) { u = Q.front(); Q.pop(); for(v=0; v<=t; v++) if( !a[v] && cap[u][v] > flow[u][v] ) { Q.push(v); a[v] = a[u] < cap[u][v] - flow[u][v] ? a[u] : cap[u][v] - flow[u][v]; pre[v] = u; } } if( a[t] == 0 ) break; for(u=t; u!=s; u=pre[u]) { flow[pre[u]][u] += a[t]; flow[u][pre[u]] -= a[t]; } f += a[t]; } return f; } int main(){ int u,v,w; char ss[32]; while(cin>>n>>np>>nc>>m){ memset(flow,0,sizeof(flow)); memset(cap,0,sizeof(cap)); int ans=0; s=n;//源点 t=n+1;//汇点 for(int i=1;i<=m;i++){ /* while(getchar()!='('); scanf("(%d,%d)%d",&u,&v,&w); */ scanf("%s",ss); sscanf(ss,"(%d,%d)%d",&u,&v,&w); cap[u][v]=w; } for(int i=0;i<np;i++){ //scanf("(%d)%d",&v,&w); scanf("%s",ss); sscanf(ss,"(%d)%d",&v,&w); cap[s][v]=w; } for(int i=0;i<nc;i++){ // scanf("(%d)%d",&u,&w); scanf("%s",ss); sscanf(ss,"(%d)%d",&u,&w); cap[u][t]=w; } ans = EKarp(); printf("%d\n",ans); } system("pause"); return 0; }
- poj 1459 最大流问题
- poj 1273 最大流问题
- POJ 1273 最大流问题
- poj 1459(最大流)
- POJ 1459 最大流
- poj 1459 (最大流)
- poj 1459 最大流
- POJ 1459 最大流
- poj 1459 最大流
- poj-1459 Power Network(网络最大流问题)
- poj-1273-Drainage Ditches(最大流问题)
- poj 1273 Drainage Ditches 最大流问题.
- 最小费用最大流问题----poj 2135
- poj 1459(最大流)
- poj 1459 多源汇最大流
- POJ 1459最大流模板
- poj 3041(最大匹配问题)
- 最大匹配问题 POJ 1274
- 关于程序员的几个笑话
- 民生银行2013年暑期实习生笔试编程题
- Zend Studio 9.0.3 支持 phpunit
- const参数,const返回值与const函数
- 9 个开始使用 C++11 的理由
- poj 1459 最大流问题
- 40岁以上的程序员该怎么办?年龄不是问题
- 移植Linux内核到mini2440常见问题
- 给自己加油!!!30岁之前一定要做出一番成就来!
- 【转】给IT新人的15个建议:苦逼程序员的辛酸反省与总结 - 博客 - 伯乐在线
- 后门攻击
- 转发:九症状自我检测肾虚程度
- 三款免费的PHP加速器:APC、eAccelerator、XCache比较
- 俄罗斯方块的设计