athos@671: // -*- c++ -*-
athos@671: #include <iostream>
athos@671: #include <fstream>
athos@671: 
athos@671: #include <sage_graph.h>
athos@671: //#include <smart_graph.h>
athos@671: #include <hugo/dimacs.h>
athos@671: #include <hugo/time_measure.h>
athos@671: #include <hugo/for_each_macros.h>
athos@671: #include <bfs_dfs.h>
athos@671: 
athos@671: using namespace hugo;
athos@671: 
athos@671: int main() {
athos@671:   typedef SageGraph Graph; 
athos@671:   typedef Graph::Node Node;
athos@671:   typedef Graph::NodeIt NodeIt;
athos@671:   typedef Graph::Edge Edge;
athos@671:   typedef Graph::EdgeIt EdgeIt;
athos@671:   typedef Graph::OutEdgeIt OutEdgeIt;
athos@671: 
athos@671:   Graph g;
athos@671:   Node s, t;
athos@671:   Graph::EdgeMap<int> cap(g);
athos@671:   //readDimacsMaxFlow(std::cin, g, s, t, cap);
athos@671:   readDimacs(std::cin, g);
athos@671: 
athos@671:   Graph::NodeMap<OutEdgeIt> pred(g);
athos@671: 
athos@671:   Timer ts;
athos@671:   /*
athos@671:   {
athos@671:     ts.reset();
athos@671:     Graph::NodeMap<bool> reached(g);
athos@671:     reached.set(s, true);
athos@671:     pred.set(s, INVALID);
athos@671:     std::queue<Node> bfs_queue;
athos@671:     bfs_queue.push(t);
athos@671:     while (!bfs_queue.empty()) {
athos@671:       Node v=bfs_queue.front();	
athos@671:       bfs_queue.pop();
athos@671:       OutEdgeIt e;
athos@671:       for(g.first(e,v); g.valid(e); g.next(e)) {
athos@671: 	Node w=g.head(e);
athos@671: 	if (!reached[w]) {
athos@671: 	  bfs_queue.push(w);
athos@671: 	  reached.set(w, true);
athos@671: 	  pred.set(w, e);
athos@671: 	}
athos@671:       }
athos@671:     }
athos@671: 
athos@671:     std::cout << ts << std::endl;
athos@671:   }
athos@671:   */
athos@671: 
athos@671:   {
athos@671:     ts.reset();
athos@671:     Graph::NodeMap<bool> bfs_reached(g);
athos@671:     Graph::NodeMap<Edge> bfs_pred(g); 
athos@671:     Graph::NodeMap<int> bfs_dist(g);
athos@671:       
athos@671:     Bfs< Graph, Graph::NodeMap<bool>, 
athos@671:       Graph::NodeMap<Edge>, Graph::NodeMap<int> > 
athos@671:       bfs(g,bfs_reached, bfs_pred, bfs_dist );
athos@671:     bfs.run(s);
athos@671:     /*
athos@671:     pred.set(s, INVALID);
athos@671:     while (!bfs.finished()) { 
athos@671:       ++bfs; 
athos@671:       if (g.valid(bfs) && bfs.isBNodeNewlyReached()) 
athos@671: 	pred.set(bfs.bNode(), bfs);
athos@671:     }
athos@671:     */
athos@671:     std::cout << ts << std::endl;
athos@671:   }
athos@671: 
athos@671:   return 0;
athos@671: }