Bzoj 1834 ZJOI2010 Network expansion Dinic+ek fee flow

Source: Internet
Author: User

Topic: Given an n-point m-edge of the graph, each edge has a capacity to increase the cost of C, representing the cost of 1 per capacity expansion, the maximum flow and the maximum flow to expand the minimum cost of K

First ask direct run Max Flow

The second question is to connect the starting point of each edge to the end of a traffic is positive infinity, the cost of C of the edge and then the N to the meeting point of a traffic for the ans+k cost of 0 of the edge run the minimum cost maximum flow can be

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 5010# Define INF 0x3f3f3f3f#define S 1#define T (n+1) using namespace std;struct edge{int x,y,f,c;} Edges[m];struct abcd{int To,f,c,next;} Table[m<<2];int head[m],tot=1;int n,m,k,ans,anscost;int dpt[m];void Add (int x,int y,int f,int c) {table[++tot].to =y;table[tot].f=f;table[tot].c=c;table[tot].next=head[x];head[x]=tot;} BOOL BFS () {static int q[m],r,h;int i;memset (dpt,-1,sizeof DPT); R=h=0;q[++r]=s;dpt[s]=1;while (r!=h) {int x=q[++h];for ( I=head[x];i;i=table[i].next) if (table[i].f&&!~dpt[table[i].to]) {dpt[table[i].to]=dpt[x]+1;q[++r]=table[ I].to;if (table[i].to==t) return true;}} return false;} int dinic (int x,int flow) {int i,left=flow;if (x==t) return flow;for (I=head[x];i&&left;i=table[i].next) if ( table[i].f&&dpt[table[i].to]==dpt[x]+1) {int temp=dinic (table[i].to,min (LEFT,TABLE[I].F)), if (!temp) dpt[ Table[i].to]=-1;left-=temp;table[i].f-=temp;table[i^1].f+=temp;} ReturnFlow-left;} BOOL EK () {static int q[65540],flow[m],cost[m],from[m];static bool V[m];static unsigned short r,h;int i;memset (cost,0x3f , sizeof cost); Cost[s]=0;flow[s]=inf;q[++r]=s;while (r!=h) {int x=q[++h];v[x]=0;for (i=head[x];i;i=table[i].next) if ( TABLE[I].F) if (cost[table[i].to]>cost[x]+table[i].c) {cost[table[i].to]=cost[x]+table[i].c;flow[table[i].to]= Min (FLOW[X],TABLE[I].F); From[table[i].to]=i;if (!v[table[i].to]) v[table[i].to]=1,q[++r]=table[i].to;} if (Cost[t]==inf) return false;anscost+=flow[t]*cost[t];for (I=from[t];i;i=from[table[i^1].to]) Table[i].f-=flow[T] , Table[i^1].f+=flow[t];return true;} int main () {int i;cin>>n>>m>>k;for (i=1;i<=m;i++) {scanf ("%d%d", &edges[i].x,&edges[i]. y); scanf ("%d%d", &edges[i].f,&edges[i].c); ADD (edges[i].x,edges[i].y,edges[i].f,0); ADD (edges[i].y,edges[i].x,0,0);} ADD (n,t,inf,0); Add (t,n,0,0), while (BFS ()) Ans+=dinic (S,inf), Table[tot-1].f=k;for (i=1;i<=m;i++) {ADD (edges[i].x,edges[i].y,inf , EDGES[I].C); ADD (edges[i].y,edges[i].x,0,-EDGES[I].C);} while (EK ());cout<<ans<< "&LT;&LT;ANSCOST&LT;&LT;ENDL;}


Bzoj 1834 ZJOI2010 Network expansion Dinic+ek fee flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.