zoj2314
来源:互联网 发布:用一淘下单算淘宝客吗 编辑:程序博客网 时间:2024/06/12 21:53
zoj又挂了
不知道对不对,先贴代码吧
无源汇有上下界网络的可行流问题http://wenku.baidu.com/view/379b6aec4afe04a1b071dedd.html
#include<iostream>#include<stdio.h>#include<string.h>#include<limits.h>#include<queue>#define MAX 400using namespace std;struct node{int y;int next;int cap;int flow;int b;}a[MAX*MAX];int h[MAX],tot=0,leve[MAX],bcap[MAX];void addedge(int i,int j,int b, int c){ a[tot].flow=0; a[tot].b=b; a[tot].y=j; a[tot].cap=c; a[tot].next=h[i]; h[i]=tot++; a[tot].flow=0; a[tot].b=-b; a[tot].y=i; a[tot].cap=0; a[tot].next=h[j]; h[j]=tot++; }bool bfs(int s,int t){int u,v,c,i;queue<int> q;memset(leve,-1,sizeof(leve));leve[s]=0;q.push(s);while(!q.empty()){u=q.front();q.pop();i=h[u];while(i!=-1){v=a[i].y;if(a[i].cap>0&&leve[v]==-1){q.push(v);leve[v]=leve[u]+1;}i=a[i].next;}}return leve[t]!=-1;}int dinic(int s,int t){int stack[MAX],last[MAX];int u,v,top=1,minf,i,temp,c,edge,sum=0;while(bfs(s,t)){top=1;stack[top]=s;for(i=s;i<=t;i++){last[i]=h[i];}while(top){u=stack[top];if(u==t){minf=INT_MAX;for(i=1;i<top;i++){edge=last[stack[i]];if(minf>a[edge].cap){minf=a[edge].cap;temp=i;}}for(i=1;i<top;i++){edge=last[stack[i]];a[edge].cap-=minf;a[edge].flow+=minf;a[edge^1].cap+=minf;a[edge^1].flow-=minf;}sum+=minf;top=temp;continue;}edge=last[u];while(edge!=-1){v=a[edge].y;c=a[edge].cap;if(c>0&&leve[u]+1==leve[v]){stack[++top]=v;break;}edge=a[edge].next;}last[u]=edge;if(edge==-1){top--;if(top!=0)last[stack[top]]=a[last[stack[top]]].next;}}}return sum;}int main(){int t,m,n,u,v,c,b,i;bool flag;scanf("%d",&t);while(t--){tot=0;memset(h,-1,sizeof(h));memset(bcap,0,sizeof(bcap));scanf("%d%d",&m,&n);flag=true;for(i=0;i<n;i++){scanf("%d%d%d%d",&u,&v,&b,&c);addedge(u,v,b,c-b);bcap[v]+=b;bcap[u]-=b;}for(i=1;i<=m;i++){if(bcap[i]>0)addedge(0,i,bcap[i],bcap[i]);else if(bcap[i]<0) {addedge(i,m+1,-bcap[i],-bcap[i]);}}dinic(0,m+1);for(u=h[0];u!=-1;u=a[u].next){if(a[u].flow!=bcap[a[u].y]){flag=false;break;}}for(u=h[m+1];u!=-1&&flag;u=a[u].next){if(a[u].flow!=bcap[a[u].y]){flag=false;break;}}if(flag==false)printf("NO\n");else{printf("YES\n");for(i=0;i<2*n;i+=2){printf("%d\n",a[i].flow+a[i].b);}}cout<<endl;}}
- zoj2314
- zoj2314
- ZOJ2314 Reactor Cooling
- zoj2314 Reactor Cooling --- 上下界可行流
- zoj2314(上下界网络流)
- 有上下界最大流初步zoj2314
- 【上下界网络流】ZOJ2314 Reactor Cooling
- 【zoj2314】Reactor Cooling 无源汇可行流)
- ZOJ2314 Reactor Cooling (有上下界的网络流)
- [ZOJ2314]/[SGU194] Reactor Cooling 无源汇有上下界网络流
- [ZOJ2314]Reactor Cooling(无源汇有上下界的可行流)
- ZOJ2314 Reactor Cooling(无源汇上下界可行流)
- [伪·ZOJ2314] 无源汇有上下界的最大流
- 【无源汇上下界可行流】ZOJ2314[Reactor Cooling]题解
- zoj2314 Reactor Cooling (无源汇的有上下界的最大流)
- 2个经典 zoj2314 无源汇有上下界最大流 并输出可行流 ZOJ3229 有源汇上下界最大流
- 使用反编译工具反编译Dll,编译成C#
- GT-Grid 1.0 基础教程(一)
- DynamSoft.SourceAnyWhere.Standalone.v4.1.Incl.Keymaker-ZWT
- 高性能IO设计的Reactor和Proactor模式
- GT-Grid 1.0 基础教程(二)
- zoj2314
- 2BrightSparks.SyncBackPro.v6.2.11.0.Multilingual.Incl.Keymaker-ZWT
- c语言链表问题,希望高手指点
- JBOSS中使用RMI不能连接服务器的原因
- hibernate配置数据库连接池的三种方法
- X-Ways.WinHex.v16.7.SR-4.Incl.Keymaker-ZWT
- c语言链表,请高手指点
- GT-Grid 1.0 基础教程(三)
- CSS处理文本内容过长