Index: src/work/marci/bfs_dfs_misc.h
===================================================================
--- src/work/marci/bfs_dfs_misc.h	(revision 552)
+++ src/work/marci/bfs_dfs_misc.h	(revision 577)
@@ -40,22 +40,45 @@
   /// I think the final version will work as an iterator
   /// if the graph is not a acyclic, the na pre-topological order is obtained 
-  /// (see Schrijver's book)
-  template<typename Graph> 
-  void topSort(const Graph& g, std::list<typename Graph::Node>& l) {
+  /// (see Schrijver's book).
+  /// PredMap have to be a writtable node-map.
+  /// If the graph is directed and not acyclic, 
+  /// then going back from the returned node via the pred information, a 
+  /// cycle is obtained.
+  template<typename Graph, typename PredMap> 
+  typename Graph::Node 
+  topSort(const Graph& g, std::list<typename Graph::Node>& l, 
+	       PredMap& pred) {
     l.clear();
     typedef typename Graph::template NodeMap<bool> ReachedMap;
+    typedef typename Graph::template NodeMap<bool> ExaminedMap;    
     ReachedMap reached(g/*, false*/);
+    ExaminedMap examined(g/*, false*/);
     DfsIterator<Graph, ReachedMap> dfs(g, reached);
     FOR_EACH_LOC(typename Graph::NodeIt, n, g) {
       if (!reached[n]) {
 	dfs.pushAndSetReached(n);
+	pred.set(n, INVALID);
 	while (!dfs.finished()) {
 	  ++dfs;
+	  if (dfs.isBNodeNewlyReached()) {
+	    ///\bug hugo 0.2-ben Edge kell
+	    pred.set(dfs.aNode(), typename Graph::OutEdgeIt(dfs));
+	  } else {
+	    ///\bug ugyanaz
+	    if (g.valid(typename Graph::OutEdgeIt(dfs)) && 
+		!examined[dfs.bNode()]) {
+	      ///\bug hugo 0.2-ben Edge kell
+	      pred.set(dfs.bNode(), typename Graph::OutEdgeIt(dfs));
+	      return dfs.aNode();
+	    }
+	  }
 	  if (dfs.isANodeExamined()) {
 	    l.push_back(dfs.aNode());
+	    examined.set(dfs.aNode(), true);
 	  }
 	}
       }
     }
+    return INVALID;
   }
 } //namespace hugo
Index: src/work/marci/bfsit_vs_byhand.cc
===================================================================
--- src/work/marci/bfsit_vs_byhand.cc	(revision 555)
+++ src/work/marci/bfsit_vs_byhand.cc	(revision 577)
@@ -20,13 +20,15 @@
   typedef Graph::OutEdgeIt OutEdgeIt;
 
-  Graph G;
+  Graph g;
   Node s, t;
-  Graph::EdgeMap<int> cap(G);
-  readDimacsMaxFlow(std::cin, G, s, t, cap);
-  Graph::NodeMap<OutEdgeIt> pred(G);
+  Graph::EdgeMap<int> cap(g);
+  //readDimacsMaxFlow(std::cin, g, s, t, cap);
+  readDimacs(std::cin, g);
+
+  Graph::NodeMap<OutEdgeIt> pred(g);
   Timer ts;
   {
     ts.reset();
-    Graph::NodeMap<bool> reached(G);
+    Graph::NodeMap<bool> reached(g);
     reached.set(s, true);
     pred.set(s, INVALID);
@@ -37,6 +39,6 @@
       bfs_queue.pop();
       OutEdgeIt e;
-      for(G.first(e,v); G.valid(e); G.next(e)) {
-	Node w=G.head(e);
+      for(g.first(e,v); g.valid(e); g.next(e)) {
+	Node w=g.head(e);
 	if (!reached[w]) {
 	  bfs_queue.push(w);
@@ -52,10 +54,10 @@
   {
     ts.reset();      
-    BfsIterator< Graph, Graph::NodeMap<bool> > bfs(G);
+    BfsIterator< Graph, Graph::NodeMap<bool> > bfs(g);
     bfs.pushAndSetReached(s);
     pred.set(s, INVALID);
     while (!bfs.finished()) { 
       ++bfs; 
-      if (G.valid(bfs) && bfs.isBNodeNewlyReached()) 
+      if (g.valid(bfs) && bfs.isBNodeNewlyReached()) 
 	pred.set(bfs.bNode(), bfs);
     }
Index: src/work/marci/lg_vs_sg.cc
===================================================================
--- src/work/marci/lg_vs_sg.cc	(revision 555)
+++ src/work/marci/lg_vs_sg.cc	(revision 577)
@@ -26,14 +26,15 @@
     typedef Graph::EdgeIt EdgeIt;
 
-    Graph G;
+    Graph g;
     Node s, t;
-    Graph::EdgeMap<int> cap(G);
+    Graph::EdgeMap<int> cap(g);
     std::ifstream ins(in.c_str());
-    readDimacsMaxFlow(ins, G, s, t, cap);
+    //readDimacsMaxFlow(ins, g, s, t, cap);
+    readDimacs(ins, g, cap, s, t);
 
     Timer ts;
-    Graph::EdgeMap<int> flow(G); //0 flow
+    Graph::EdgeMap<int> flow(g); //0 flow
     MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
-      max_flow_test(G, s, t, cap, flow/*, true*/);
+      max_flow_test(g, s, t, cap, flow/*, true*/);
 
     std::cout << "ListGraph ..." << std::endl;
@@ -49,5 +50,5 @@
     {
       std::cout << "physical blocking flow augmentation ..." << std::endl;
-      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+      FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
       ts.reset();
       int i=0;
@@ -60,5 +61,5 @@
 //     {
 //       std::cout << "faster physical blocking flow augmentation ..." << std::endl;
-//       FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+//       FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
 //       ts.reset();
 //       int i=0;
@@ -71,5 +72,5 @@
     {
       std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
-      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+      FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
       ts.reset();
       int i=0;
@@ -82,5 +83,5 @@
     {
       std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
-      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+      FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
       ts.reset();
       int i=0;
@@ -98,16 +99,17 @@
     typedef Graph::EdgeIt EdgeIt;
 
-    Graph G;
+    Graph g;
     Node s, t;
-    Graph::EdgeMap<int> cap(G);
+    Graph::EdgeMap<int> cap(g);
     std::ifstream ins(in.c_str());
-    readDimacsMaxFlow(ins, G, s, t, cap);
+    //readDimacsMaxFlow(ins, g, s, t, cap);
+    readDimacs(ins, g, cap, s, t);
 
     Timer ts;
-    Graph::EdgeMap<int> flow(G); //0 flow
+    Graph::EdgeMap<int> flow(g); //0 flow
     MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
-      max_flow_test(G, s, t, cap, flow/*, true*/);
+      max_flow_test(g, s, t, cap, flow/*, true*/);
     //    MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
-    //  max_flow_test(G, s, t, cap, flow);
+    //  max_flow_test(g, s, t, cap, flow);
 
     std::cout << "SmatrGraph ..." << std::endl;
@@ -115,5 +117,5 @@
     {
       std::cout << "preflow ..." << std::endl;
-      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+      FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
       ts.reset();
       max_flow_test.run();
@@ -124,5 +126,5 @@
     {
       std::cout << "physical blocking flow augmentation ..." << std::endl;
-      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+      FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
       ts.reset();
       int i=0;
@@ -135,5 +137,5 @@
 //     {
 //       std::cout << "faster physical blocking flow augmentation ..." << std::endl;
-//       FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+//       FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
 //       ts.reset();
 //       int i=0;
@@ -146,5 +148,5 @@
     {
       std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
-      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+      FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
       ts.reset();
       int i=0;
@@ -157,5 +159,5 @@
     {
       std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
-      FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+      FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
       ts.reset();
       int i=0;
Index: src/work/marci/max_flow_demo.cc
===================================================================
--- src/work/marci/max_flow_demo.cc	(revision 555)
+++ src/work/marci/max_flow_demo.cc	(revision 577)
@@ -64,12 +64,13 @@
 
 
-  Graph G;
+  Graph g;
   Node s, t;
-  Graph::EdgeMap<int> cap(G);
-  readDimacsMaxFlow(std::cin, G, s, t, cap);
+  Graph::EdgeMap<int> cap(g);
+  //readDimacsMaxFlow(std::cin, g, s, t, cap);
+  readDimacs(std::cin, g, cap, s, t);
   Timer ts;
-  Graph::EdgeMap<int> flow(G); //0 flow
+  Graph::EdgeMap<int> flow(g); //0 flow
   MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > 
-    max_flow_test(G, s, t, cap, flow);
+    max_flow_test(g, s, t, cap, flow);
 
   {
@@ -83,5 +84,5 @@
   {
     std::cout << "preflow ..." << std::endl;
-    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+    FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
     ts.reset();
     max_flow_test.preflow(MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >::GEN_FLOW);
@@ -92,5 +93,5 @@
 //   {
 //     std::cout << "wrapped preflow ..." << std::endl;
-//     FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+//     FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
 //     ts.reset();
 //     pre_flow_res.run();
@@ -101,5 +102,5 @@
   {
     std::cout << "physical blocking flow augmentation ..." << std::endl;
-    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+    FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
     ts.reset();
     int i=0;
@@ -112,5 +113,5 @@
 //   {
 //     std::cout << "faster physical blocking flow augmentation ..." << std::endl;
-//     FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+//     FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
 //     ts.reset();
 //     int i=0;
@@ -123,5 +124,5 @@
   {
     std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
-    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+    FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
     ts.reset();
     int i=0;
@@ -134,5 +135,5 @@
   {
     std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
-    FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
+    FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
     ts.reset();
     int i=0;
Index: src/work/marci/top_sort.dim
===================================================================
--- src/work/marci/top_sort.dim	(revision 552)
+++ src/work/marci/top_sort.dim	(revision 577)
@@ -3,4 +3,4 @@
 a 2 3
 a 3 5
-a 3 4
+a 4 3
 a 5 4
Index: src/work/marci/top_sort_test.cc
===================================================================
--- src/work/marci/top_sort_test.cc	(revision 557)
+++ src/work/marci/top_sort_test.cc	(revision 577)
@@ -8,4 +8,5 @@
 #include <list_graph.h>
 #include <hugo/graph_wrapper.h>
+#include <hugo/maps.h>
 
 using namespace hugo;
@@ -17,5 +18,6 @@
   {
     std::list<Graph::Node> l;
-    topSort(g, l);
+    NullMap<Graph::Node, Graph::Edge> pred;
+    topSort(g, l, pred);
     std::cout << "Leaving order of dfs which is pretopological..." << std::endl;
     for(std::list<Graph::Node>::const_iterator i=l.begin(); i!=l.end(); ++i) {
@@ -29,5 +31,6 @@
     GW gw(g);
     std::list<GW::Node> l;
-    topSort(gw, l);
+    NullMap<GW::Node, GW::Edge> pred;
+    topSort(gw, l, pred);
     std::cout << "Same in the revered oriented graph..." << std::endl;
     for(std::list<GW::Node>::const_iterator i=l.begin(); i!=l.end(); ++i) {
