poj 1273 maxflow 模版题
来源:互联网 发布:男装高端尾货淘宝店 编辑:程序博客网 时间:2024/06/07 19:55
连连模版把
自己对反向边的理解还不深刻!用vector比用二维数组要好!
#include<iostream>using namespace std;#include<vector>#include<cstdio>#include<algorithm>#include<cstring>const int maxn=205;const int inf=0x3f3f3f3f;typedef struct notes{ int aim,f,rev,st;}note;vector<note> G[maxn];int rev_[maxn];bool used[maxn];///int n,m;void Add_E(int u,int v,int c){ note temp; temp.aim=v; temp.f=c; temp.rev=G[v].size(); G[u].push_back(temp); temp.aim=u; temp.f=0;/// temp.rev=G[u].size()-1; G[v].push_back(temp);}int min_(int aa,int bb){ return aa>bb?bb:aa;}int dfs(int s,int e,int c_flow){// printf("s=%d e=%d\n",s,e); if(s==e)return c_flow; int size_=G[s].size(),fl; used[s]=true; for(int i=0;i<size_;i++){ note &num=G[s][i];// printf("e=%d\n",G[s][i].aim); if(num.f<=0)continue; if(used[G[s][i].aim])continue; used[num.aim]=true; fl=dfs(G[s][i].aim,e,min_(num.f,c_flow)); if(fl>0){ num.f-=fl; G[num.aim][num.rev].f+=fl; return fl; } } return 0;}int maxflow(int s,int e){ int ans=0,flag;// memset(rev_,-1,sizeof(rev_)); memset(used,false,sizeof(used)); while(flag=dfs(s,e,inf)){// printf("flag=%d\n",flag); if(flag==inf||flag==0)break; ans+=flag; memset(used,false,sizeof(used)); } return ans;}int main(){ #ifdef ONLINE_JUDGE #else freopen("1273.txt","r",stdin); #endif // ONLINE_JUDGE while(scanf("%d%d",&n,&m)!=-1){ for(int i=0;i<maxn;i++){ G[i].clear(); } for(int i=0;i<n;i++){ int u,v,c; scanf("%d%d%d",&u,&v,&c); Add_E(u,v,c); } printf("%d\n",maxflow(1,m)); } return 0;}
0 0
- poj 1273 maxflow 模版题
- poj 1273 Drainage Ditches---maxflow最大流
- poj 3281 Dining Maxflow
- POJ 1149 PIGS //MAXFLOW
- maxflow
- MaxFLOW
- poj 3281 Dinic模版题
- poj 1469 匈牙利模版题
- poj 1001 Exponentiation(模版题)
- poj 1330 LCA模版题
- poj 1830 高斯消元模版题
- POJ 3974 Manacher模版题
- POJ-3461(KMP模版题)
- POJ:1273 Drainage Ditches(网络最大流模版题)
- poj 1273 Drainage Ditches(网络流模版题)
- poj 1273 Drainage Ditches_最大流模版
- POJ 1273 Drainage Ditches 网络流模版
- poj 3264 RMQ 线段树模版题
- python的第一天
- 常用拼接多个查询条件的方法01
- 第五篇 使用category action data启动特定的Activity
- 门户应用Apache Jetspeed 2.3.0及早期版本:远程代码执行漏洞分析
- JSP继续学习(完成一个最简单的用户登录界面)
- poj 1273 maxflow 模版题
- Unity2D 通过Canvas来设置屏幕适配
- 最短路 dijkstra
- 83. Remove Duplicates from Sorted List
- C++11之右值引用
- 深入理解计算机系统之链接(三)
- VC中获取字符串长度的四种类型
- day11—DAO
- 老罗Handler(21)下载图片,Runnable,Handler,Message