HDU 3549Flow Problem(网络流之最大流)
来源:互联网 发布:绝地求生优化太垃圾了 编辑:程序博客网 时间:2024/04/27 23:04
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3549
纯水题。。只是想拿来练习下模板的熟练度而已。。这次一气呵成,爽。。
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int head[100], s, t, nv, maxint=999999, cnt, num1;int cur[100], num[100], d[100], q[10000],pre[100];struct node{ int u, v, next; int cap;}edge[10000];void add(int u, int v, int cap){ edge[cnt].v=v; edge[cnt].cap=cap; edge[cnt].next=head[u]; head[u]=cnt++; edge[cnt].v=u; edge[cnt].cap=0; edge[cnt].next=head[v]; head[v]=cnt++;}void bfs(){ memset(num,0,sizeof(num)); memset(d,-1,sizeof(d)); int f1=0, f2=0, i; q[f1++]=t; d[t]=0; num[0]=1; while(f1>=f2) { int u=q[f2++]; for(i=head[u];i!=-1;i=edge[i].next) { int v=edge[i].v; if(d[v]==-1) { d[v]=d[u]+1; num[d[v]]++; q[f1++]=v; } } }}void isap(){ memcpy(cur,head,sizeof(cur)); bfs(); int flow=0, u=pre[s]=s, i; while(d[s]<nv) { if(u==t) { int f=maxint, pos; for(i=s;i!=t;i=edge[cur[i]].v) { if(f>edge[cur[i]].cap) { f=edge[cur[i]].cap; pos=i; } } for(i=s;i!=t;i=edge[cur[i]].v) { edge[cur[i]].cap-=f; edge[cur[i]^1].cap+=f; } flow+=f; u=pos; } for(i=cur[u];i!=-1;i=edge[i].next) { if(d[edge[i].v]+1==d[u]&&edge[i].cap) { break; } } if(i!=-1) { cur[u]=i; pre[edge[i].v]=u; u=edge[i].v; } else { if(--num[d[u]]==0) break; int mind=nv; for(i=head[u];i!=-1;i=edge[i].next) { if(mind>d[edge[i].v]&&edge[i].cap) { cur[u]=i; mind=d[edge[i].v]; } } d[u]=mind+1; num[d[u]]++; u=pre[u]; } } printf("Case %d: %d\n",num1,flow);}int main(){ int tt, m, a, b, c, i, n; scanf("%d",&tt); num1=0; while(tt--) { num1++; scanf("%d%d",&n,&m); memset(head,-1,sizeof(head)); cnt=0; while(m--) { scanf("%d%d%d",&a,&b,&c); add(a,b,c); } s=1; t=n; nv=t+1; isap(); } return 0;}
0 0
- HDU 3549Flow Problem(网络流之最大流)
- HDU 3549 Flow Problem 最大网络流
- hdu 3549 最大网络流 Flow Problem
- hdu - 3549 - Flow Problem(最大流)
- HDU 3549 Flow Problem(最大流)
- HDU 3549 Flow Problem(最大流)
- HDU 3549 Flow Problem (最大流)
- hdu 3549 Flow Problem(最大流)
- HDU- 3549-Flow Problem (网络流之 EK)
- HDU 3549 Flow Problem(网络流之最大流模板题)
- HDU-3549 Flow Problem【最大流】
- hdu 3549 Flow Problem【最大流】
- hdu 3549 Flow Problem 最大流
- hdu 3549 Flow Problem (最大流)
- Hdu 3549 Flow Problem - 最大流
- hdu 3549 Flow Problem(最大流)
- HDU 3549 Flow Problem (最大流)
- HDU 3549--Flow Problem【最大流】
- Unicode与FFFE(记一个蛋疼的项目)
- Android 源代码中增加新apk
- View及ViewGroup的事件分发及传递(二)
- ios 加载本地的Html文件
- 笔记 第22章软件安装和tarball包 鸟哥的linux私房菜第三版
- HDU 3549Flow Problem(网络流之最大流)
- *.exe 中发生了缓冲区溢出
- 对账简单说
- cclabelttf字体不显示的解决办法
- VS2010下配置GTK+2.0
- ACDream 1101 瑶瑶想要玩滑梯 线段树
- oracle 中 cursor 与refcursor及sys_refcursor的区别 (转载)
- OCP 1Z0 052 94
- xml中子元素与属性有什么区别和关系?