// Input: a directed graph G s.t. // for all edge e, e.cost is a real number and no negative // cycles and a starting node n // // At the beginning we assume all backpointers to be NIL // and for each node n, n.cost to be +infinity // // Output: a modified graph G s.t. for all nodes m reachable // from n in G, n.backpointer points to the previous node // in a path of minimal cost from n to m // // FordFulkerson \in O(|E|*|V|) FordFulkerson(G,n) { n.cost := 0 for each v in V do for each (u,w) in E of cost k do if u.cost + k < w.cost then w.cost := u.cost + k w.backpointer := u }