标签:set pre size har mem amp min return while
bool spfa(){ queue<int>que; que.push(s); memset(dis,INF,sizeof(dis)); dis[s]=0; while(!que.empty()){ int u=que.front(); que.pop(); vis[u]=0; for(int i=head[u];~i;i=edge[i].nextt){ int v=edge[i].v; if(edge[i].w&&dis[v]>dis[u]+edge[i].cost){ dis[v]=dis[u]+edge[i].cost; if(!vis[v]) que.push(v),vis[v]=1; } } } return dis[t]!=INF; } int dfs(int u,int fl){ if(u==t){ return fl; } int ans=0; vis[u]=1; for(int i=cur[u];~i;i=edge[i].nextt){ int v=edge[i].v; if(!vis[v]&&edge[i].w&&dis[v]==dis[u]+edge[i].cost){ cur[u]=i; int x=dfs(v,min(fl-ans,edge[i].w)); ans+=x; edge[i].w-=x; edge[i^1].w+=x; mincost+=x*edge[i].cost; if(ans==fl) break; } } vis[u]=0; return ans; } void MCMF(){ while(spfa()){ for(int i=0;i<=t;i++) cur[i]=head[i]; dfs(s,INF); } }
标签:set pre size har mem amp min return while
原文地址:https://www.cnblogs.com/starve/p/10891576.html