poj 1273
来源:互联网 发布:唐之语淘宝旗航店旗袍 编辑:程序博客网 时间:2024/04/29 13:10
网络流最基础的题目,最大流
#include <iostream>#include <cstring>#include <queue>using namespace std;const int maxn=210;const int inf=1<<30;int cap[maxn][maxn],flow[maxn][maxn],d[maxn];int n,m,tot;void ek(){int q[maxn],p[maxn],i;int front,rear;for(;;){memset(d,0,sizeof(d));front=rear=0;q[rear++]=1;d[1]=inf;while(rear-front>0){int u=q[front];for(i=1;i<=m;i++){if(!d[i]&&cap[u][i]>flow[u][i]){p[i]=u;q[rear++]=i;d[i]=d[u]>(cap[u][i]-flow[u][i])?(cap[u][i]-flow[u][i]):d[u];}}front++;}if(!d[m]) break;int tem;for(tem=m;tem!=1;tem=p[tem]){flow[p[tem]][tem]+=d[m];flow[tem][p[tem]]-=d[m];}tot+=d[m];}return;}int main(){while(cin>>n>>m){int i,u,v,f;tot=0;memset(cap,0,sizeof(cap));memset(flow,0,sizeof(flow));for(i=0;i<n;i++){cin>>u>>v>>f;cap[u][v]+=f;}ek();cout<<tot<<endl;}return 0;}
- POJ 1273
- poj 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273
- POJ-1273
- poj-1273
- poj 1273
- poj 1273
- poj 1273
- POJ 1273
- poj 1273
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- POJ 1273 Drainage Ditches
- javascript获取随机颜色的函数
- UI 模式类之一----数据输入模式
- jena基本使用
- 《经典精彩Lib翻译》系列之libiconv (2)ICONV程序
- List使用总结
- poj 1273
- [Android实例] android 蓝牙开发浅析 [转]
- Http_Status_Codehttp响应状态码
- ACM zoj 1955(四分树实现)
- 可可肉的逻辑题---(九)可可肉的水仙花(上)
- 《经典精彩Lib翻译》系列之libiconv (3)ICONV_OPEN函数
- 深入理解Hadoop集群和网络
- jena实例
- 《经典精彩Lib翻译》系列之libiconv (4)ICONV函数