Title Link: http://poj.org/problem?id=1459
Problem Solving Report:
The power dispatching station does not involve the generation and consumption of the flow, regardless of the edmonds-karp algorithm, is to use the remaining network and the augmented path to solve the maximum flow in the network.
Principle: The remaining network, is a kind of fallback, constructs after the remaining network, in the remaining network to find an augmented road, wherein the minimum flow, each side plus this minimum flow or minus this minimum flow, then the flow becomes the largest.
When adding or subtracting this minimum flow, initialize flow[][] This remaining network is 0, the minimum traffic node[v]=min (Node[u],cap[u][v]-flow[u][v]), and re-update flow[][]+=node[t], is the real rest of the network, Cap[u][v]-flow[u][v] is the largest flow of this side, it can be seen here to initialize the flow[][] for the purpose of 0.
Then, the search for augmented road, BFS breadth first search out each augmented road, did not find an augmented road, update flow remaining network, until there is no augmented road, that is, until the original network without any can add the stream.
This topic, can not be directly used in the traditional sense of the maximum flow, because so there is no absolute source and sink point, so to build a super source point S, and Super Sink point, n,n+1;
#include <stdio.h>#include<string.h>#include<queue>#include<algorithm>#defineMAX 120using namespacestd;intN///Number of nodesintNp///number of power stationsintnc///Number of consumersintM///number of transmission linesintCap[max][max];///adjacency matrix of the networkint from, To,value;///The formal parameter s is the super source point, and the parameter T is the super sink pointintEkarp (intSintt) {queue<int> Q;///Search queue for BFS intFlow[max][max];///adjacency matrix for remaining networks intPre[max];///Augmented Path intNode[max];///minimum flow on an augmented path intu,v; intmaxflow=0;///maximum flow of the network///initialization of the remaining networkmemset (Flow,0,sizeof(flow)); ///constantly looking for augmented paths while(true) {Q.push (s); memset (node,0,sizeof(node)); Node[s]=100000;///minimum flow value, Infinity///BFS algorithm, search augmented path while(!Q.empty ()) {u=Q.front (); Q.pop (); for(v=0; v<=t; v++) { if(!node[v]&&cap[u][v]>Flow[u][v]) {Q.push (v); NODE[V]=min (node[u],cap[u][v]-Flow[u][v]); PRE[V]=u; } } } ///when the bottleneck capacity is 0 o'clock, there is no augmented path, the search ends if(node[t]==0) Break; ///update remaining network based on augmented path and bottleneck capacity for(u=t; u!=s; u=Pre[u]) {Flow[pre[u]][u]+=Node[t]; Flow[u][pre[u]]-=Node[t]; } Maxflow+=Node[t]; } returnMaxflow;///Total Flow Accumulation}intMain () { while(SCANF ("%d%d%d%d", &n,&np,&nc,&m)! =EOF) {memset (Cap,0,sizeof(CAP)); ///reading data from a transmission line while(m--) {scanf ("(%d,%d)%d",& from,&to,&value); cap[ from][to]=value; } ///reading power station data, constructing super source points while(np--) {scanf ("(%d)%d",& from,&value); cap[n][ from]=value; } ///read consumer data, construct a super meeting point while(nc--) {scanf ("(%d)%d",& from,&value); cap[ from][n+1]=value; } printf ("%d\n", Ekarp (n,n+1)); } return 0;}
View Code
Edmonds-karp algorithm, max Flow POJ (1459)