最大流
来源:互联网 发布:sqlalchemy sql注入 编辑:程序博客网 时间:2024/06/05 16:33
- <span style="font-size:14px;">#define N 10000
- int n,m,len,s,t;
- struct node{
- int x,y,e,pre;
- };
- node a[N*2];
- int pre[N],que[N],stage[N];
- void init()
- {
- len=0; s=0; t=m+n+1;//s和t自己改的
- memset(pre,-1,sizeof(pre));
- }
- void addpage(int x,int y,int t)
- {
- a[len].x=x;a[len].y=y;a[len].e=t;
- a[len].pre=pre[x];pre[x]=len++;
- }
- bool bfs()
- {
- queue<int>q;
- memset(stage,-1,sizeof(stage));
- stage[s]=0; q.push(s);
- while(!q.empty())
- {
- int x=q.front(); q.pop();
- for(int i=pre[x]; i!=-1; i=a[i].pre)
- if(a[i].e>0 && stage[a[i].y]==-1)
- {
- stage[a[i].y]=stage[a[i].x]+1;
- q.push(a[i].y);
- if(a[i].y==t) return true;
- }
- }
- return false;
- }
- int dfs()
- {
- int sum=0;
- while(bfs())
- {
- int tail=0,u=s;
- while(true)
- {
- if(u==t)
- {
- int Min=inf,mark;
- rep(i,tail)
- if(a[que[i]].e<Min)
- mark=i,Min=a[que[i]].e;
- rep(i,tail)
- a[que[i]].e-=Min,a[que[i]^1].e+=Min;
- sum+=Min,tail=mark,u=a[que[tail]].x;
- }
- int i;
- for( i=pre[u]; i!=-1; i=a[i].pre)
- {
- int y=a[i].y;
- if(stage[y]==-1) continue;
- if(stage[y]==stage[u]+1 && a[i].e>0) break;
- }
- if(i!=-1)//回朔
- que[tail++]=i,u=a[i].y;
- else
- {
- if(tail==0) break;
- stage[u]=-1;
- u=a[que[--tail]].x;
- }
- }
- }
- return sum;
- }
- int main()
- {
- init();
- //加正反边
- return dfs();
- return 0;
- }</span>
0 0
- 最大流-最大利益
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- 最大流
- Error: The input doesn't contain any classes. Did you specify the proper '-injars' options?
- 修改默认的/tmp/mysqk.sock路径
- 欢迎使用CSDN-markdown编辑器
- 割点和割边
- leetcode 第83题 Remove Duplicates from Sorted List
- 最大流
- 分布式系统互斥算法---非集中式算法
- OC之第四章,C语言特性
- Swift - Swift生成随机数
- 玩转html5<canvas>画图
- ECMAScript5 严格模式,JSON,及其它
- C++中构造函数与析构函数执行顺序
- 二分图的最大带权匹配
- 数据结构与算法——线性表链式存储结构(静态链表)