// Derived from // http://www.aduni.org/courses/algorithms/handouts/Reciation_09.html#25630 // The Ford-Fulkerson Algorithm in C #include // Basic Definitions #define WHITE 0 #define GRAY 1 #define BLACK 2 #define MAX_NODES 1000 #define oo 1000000000 // Declarations int n; // number of nodes int e; // number of edges int capacity[MAX_NODES][MAX_NODES]; // capacity matrix int flow[MAX_NODES][MAX_NODES]; // flow matrix int color[MAX_NODES]; // needed for breadth-first search int pred[MAX_NODES]; // array to store augmenting path int min (int x, int y) { return x0) { enqueue(v); pred[v] = u; } } } // If the color of the target node is black now, // it means that we reached it. return color[target]==BLACK; } // Ford-Fulkerson Algorithm int max_flow (int source, int sink) { int i,j,u; // Initialize empty flow. int max_flow = 0; for (i=0; i0) printf("%d->%d has %d\n",i,j,flow[i][j]); return 0; }