Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1834
Description given a forward graph, each edge has a capacity of C and an expansion fee of W. The expansion fee here refers to the cost of expanding the capacity by 1. 1, in the case of no expansion, the maximum flow of 1 to N, 2, the maximum flow of 1 to n increases the minimum cost of expansion required by K. The first line of the input file contains three integer n,m,k, indicating the number of points, sides, and the amount of traffic required to the graph. The next M-line contains four integer u,v,c,w, representing an edge from U to V with a capacity of C and a expansion fee of W. The output file row contains two integers that represent the answers to question 1 and question 2, respectively.
is to learn a fee flow template, make it to bzoj on the Infinity tle
Downloaded to the data, found that the data is "wrong", and then found that there are some Windows/dos format is a UNIX format ...
And then, found that the program in half read in the time will be collapsed, open debugging took me into the head file, thinking that I met the greatest metaphysics of the OI career
Then in the car to come to school suddenly think of their record side of the array opened small, MAXM dozen into MAXN ...
Really "metaphysics", originally is a low-level mistake in mischief ...
It seems like I've wasted a lot of time.
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <queue>6 #defineRep (i,l,r) for (int i=l; i<=r; i++)7 #defineCLR (x, y) memset (x,y,sizeof (×))8 #defineTravel (x) for (Edge *p=last[x]; p; p=p->pre)9 using namespacestd;Ten Const intINF =0x3f3f3f3f; One Const intMAXN =1010; A Const intMAXM =5010; -InlineintRead () { - intAns =0, F =1; the Charc =GetChar (); - for(;!isdigit (c); C =GetChar ()) - if(c = ='-') F =-1; - for(; IsDigit (c); C =GetChar ()) +Ans = ans *Ten+ C-'0'; - returnAns *F; + } A structedge{ atEdge *pre,*rev;intTo,cap,cost; -}edge[maxm<<2],*last[maxn],*cur[maxn],*pre[maxn],*pt; - intn,m,k,u[maxm],v[maxm],c[maxm],x,d[maxn],s,t; - BOOLISIN[MAXN]; -Queue <int>Q; -Inlinevoidinit () { inCLR (Last,0); PT =Edge; - } toInlinevoidAddintXintYintZintW) { +Pt->pre = Last[x]; Pt->to = y; Pt->cap = Z; Pt->cost = W; LAST[X] = pt++; -Pt->pre = Last[y]; Pt->to = x; Pt->cap =0; Pt->cost =-W; Last[y] = pt++; theLast[x]->rev = Last[y]; Last[y]->rev =Last[x]; * } $ BOOLBFs () {Panax Notoginseng while(!q.empty ()) Q.pop (); -CLR (d,-1); D[s] =0; Q.push (S); the while(!Q.empty ()) { + intnow =Q.front (); Q.pop (); A Travel (now) { the if(P->cap >0&& D[p->to] = =-1){ +D[p->to] = D[now] +1; -Q.push (p->to ); $ if(p->to = = T)return 1; $ } - } - } the return 0; - }Wuyi intDfsintXintflow) { the if(x = = T | | (!flow))returnFlowintW =0; - for(Edge *p = cur[x]; p && w < flow; p = p->pre) { Wu if(D[p->to] = = D[x] +1&& P->cap >0){ - intDelta = DFS (p->to,min (p->cap,flow-W)); AboutP->cap-= Delta; P->rev->cap + = Delta; W + =Delta; $ if(p->cap) Cur[x] =p; - } - } - if(W < flow) D[x] =-1; A returnW; + } the intMaxflow () { - intAns =0; $ while(BFS ()) { theRep (I,1, n) cur[i] =Last[i]; theAns + = DFS (S,0x7fffffff); the } the returnans; - } in BOOLSPFA () { the while(!q.empty ()) Q.pop (); theCLR (D,inf); CLR (Isin,0); AboutD[s] =0; Isin[s] =1; Q.push (S); the while(!Q.empty ()) { the intnow = Q.front (); Q.pop (); Isin[now] =0; the Travel (now) { + if(P->cap && d[p->to] > D[now] + p->Cost ) { -D[p->to] = D[now] + p->Cost ; thePre[p->to] =p;Bayi if(!isin[p->to ]) { theIsin[p->to] =1; Q.push (p->to ); the } - } - } the } the returnD[T]! =INF; the } the intMincost () { - intCost =0;intx =INF; the while(SPFA ()) { the for(Edge *p = pre[t]; p; p = pre[p->rev->to]) x = min (x,p->cap); the for(Edge *p = pre[t]; p; p = pre[p->rev->to ]) {94Cost + = x * p->cost; P->cap-= x; P->rev->cap + =x; the } the } the returnCost ;98 } About intMain () { -n = read (); m = read (); K =read (); Init ();101Rep (I,1, M) {102U[i] = read (); V[i] = read (); x = Read (); C[i] =read ();103Add (U[i],v[i],x,0);104 } theS =1; T = n; printf"%d", Maxflow ());106S =0; T = n +1;107Rep (I,1, M) Add (U[i],v[i],inf,c[i]); 108Add0,1K0); Add (n,n+1K0);109printf"%d\n", Mincost ()); the return 0;111}
View Code
BZOJ1834 [ZJOI2010] Network expansion