最小费用最大流
来源:互联网 发布:软件开发立项 编辑:程序博客网 时间:2024/04/29 09:51
const int N=1100,INF=0x3f3f3f3f;const int M=N*N;int pre[N],d[N],p[N],ans;int cnt,head[N];int q[M],l,r;struct edge{ int u,v,w,c,next;}e[M];void init(){<span style="white-space:pre"></span>memset(head,-1,sizeof(head)); ans=cnt=0;}void add(int u,int v,int w,int c){ e[cnt].u=u,e[cnt].v=v,e[cnt].w=w,e[cnt].c=c; e[cnt].next=head[u],head[u]=cnt++; e[cnt].u=v,e[cnt].v=u,e[cnt].w=-w,e[cnt].c=0; e[cnt].next=head[v],head[v]=cnt++;}void updata(int s,int t){ int i,f=INF; for(i=t;i!=s;i=e[pre[i]].u) f=min(f,e[pre[i]].c); for(i=t;i!=s;i=e[pre[i]].u) { e[pre[i]].c-=f; e[pre[i]^1].c+=f; ans+=f*e[pre[i]].w; }}int spfa(int s,int t){ int i,u,v,w; memset(p,0,sizeof(p)); memset(pre,-1,sizeof(pre)); memset(d,0x3f,sizeof(d)); l=r=0; q[++r]=s,p[s]=1,d[s]=0; while(l<r) { p[u=q[++l]]=0; for(i=head[u];i!=-1;i=e[i].next) { v=e[i].v,w=e[i].w; if(e[i].c&&d[v]>d[u]+w) { d[v]=d[u]+w; pre[v]=i; if(!p[v]) { p[v]=1; q[++r]=v; } } } } if(pre[t]==-1) return 0; return 1;}
0 0
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 【最小费用最大流】
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 最小费用最大流
- 基于LDA的Topic Model变形
- Java中的八种数据类型
- 初识Java注解
- Java深度历险(一)Java字节代码的操纵
- 英语介词用法
- 最小费用最大流
- HDU 5399 Too Simple (2015年多校比赛第9场)
- Struts2 国际化
- 数据结构之---C语言实现最短路径之Dijkstra(迪杰斯特拉)算法
- POJ 1591 M*A*S*H 水模拟
- 通知
- 《断舍离》笔记二
- 存在即更新反之插入的三种防唯一键冲突和死锁的写法
- [leetcode-142]Linked List Cycle II(c)