Billing flow is the maximum minimum fee flow.
First paste the template on the powder book:
Struct edge {int from, to, Cap, flow, cost; edge (int u, int V, int C, int F, int W): From (u ), to (V), Cap (C), flow (F), Cost (w) {}}; int n, m; vector <edge> edges; vector <int> G [maxn]; int INQ [maxn]; int d [maxn]; int P [maxn]; int A [maxn]; void Init (int n) {// This-> N = N; the original Chinese version of the fan book contains this sentence, but it will obviously report an error. I feel that removing it has no effect... for (INT I = 0; I <n; I ++) g [I]. clear (); edges. clear ();} void addedge (int from, int to, int cap, int cost) {edges. push_back (edge (from, to, Cap, 0, cost); edges. push_back (edge (to, from, 0, 0,-cost); M = edges. size (); G [from]. push_back (m-2); G [to]. push_back (m-1);} bool bellmanford (int s, int T, Int & flow, long & cost) // The queue has been optimized, it feels like spfa {for (INT I = 0; I <n; I ++) d [I] = inf; memset (INQ, 0, sizeof (INQ )); d [s] = 0; INQ [s] = 1; p [s] = 0; A [s] = inf; queue <int> q; q. Push (s); While (! Q. empty () {int u = Q. front (); q. pop (); INQ [u] = 0; For (INT I = 0; I <G [u]. size; I ++) {edge & E = edges [G [u] [I]; If (E. cap> E. flow & D [E. to]> d [u] + E. cost () {d [E. to] = d [u] + E. cost; P [E. to] = G [u] [I]; A [E. to] = min (A [u], E. cap-e.flow); If (! INQ [E. to]) {q. push (E. to); INQ [E. to] = 1 ;}}}if (d [T] = inf) return false; flow + = A [T]; Cost + = (long) d [T] * (long) A [T]; for (INT u = T; u! = S; u = edges [p [u]. from) {edges [p [u]. flow + = A [T]; edges [p [u] ^ 1]. flow-= A [T];} return true;} int mcmf (int s, int T, long & cost) // S: start point; T: Sink point; {int flow = 0; cost = 0; // flow: calculates the largest stream cost: calculates the fee while (bellmanford (S, T, flow, cost )); return flow ;}
View code
Exercise: poj2516