Dinits blocking flow added to edmonds_karp_demo.hh.
4 Performs a bfs on the out Edges. It does not count predecessors,
5 only the distances, but one can easily modify it to know the pred as well.
9 reverse_bfs(Graph& G, NodeIt t)
15 void run(): runs a reverse bfs from t
17 The following function should be used after run() was already run.
19 int dist(NodeIt v) : returns the distance from v to t. It is the number of nodes if t is not reachable from v.
26 #include <list_graph.hh>
31 template <typename Graph>
33 typedef typename Graph::NodeIt NodeIt;
34 typedef typename Graph::EachNodeIt EachNodeIt;
35 typedef typename Graph::InEdgeIt InEdgeIt;
40 typename Graph::NodeMap<int> distance;
46 The distance of the Nodes is n, except t for which it is 0.
48 reverse_bfs(Graph& _G, NodeIt _t) : G(_G), t(_t), distance(G, G.nodeNum()) {
54 typename Graph::NodeMap<bool> reached(G, false);
57 std::queue<NodeIt> bfs_queue;
60 while (!bfs_queue.empty()) {
62 NodeIt v=bfs_queue.front();
65 for(InEdgeIt e=G.template first<InEdgeIt>(v); e.valid(); ++e) {
67 if (!reached.get(w)) {
69 distance.set(w, distance.get(v)+1);
79 return distance.get(v);
87 #endif //REVERSE_BFS_HH