Index: src/include/bfs.h
===================================================================
--- src/include/bfs.h	(revision 6)
+++ src/include/bfs.h	(revision 8)
@@ -46,6 +46,6 @@
   
   struct do_nothing_map {
-    template <typename V,typename T>
-    static void Put(V v,T t) {}
+    template <typename V,typename T> static void Put(V v,T t) {}
+    template <typename G> void SetG(G &g) {}
   };
   
@@ -283,7 +283,14 @@
     Graph *G;
     
+    //Bfs(int i): visited_map(G), tree_map(G), dist_map(G), priority_map(G) {}
+    Bfs() {}
+
     void SetG(Graph &Gr)
     {
       G=&Gr;
+      visited_map.SetG(Gr);
+      tree_map.SetG(Gr);
+      dist_map.SetG(Gr);
+      priority_map.SetG(Gr);
     }
     
Index: src/include/graph.h
===================================================================
--- src/include/graph.h	(revision 6)
+++ src/include/graph.h	(revision 8)
@@ -76,5 +76,5 @@
       bool operator!=(const NodeIterator &i) const {return n!=i.n;}
       
-      int Index() { return n; } //If the nodes are indexable 
+      int Index() const { return n; } //If the nodes are indexable 
       friend class Graph;
       friend class EdgeIterator;
@@ -120,5 +120,5 @@
       bool operator!=(const EdgeIterator &i) const {return e!=i.e;}
        
-      int Index() { return e.index.block*EDGE_BLOCK_SIZE+e.index.index; }
+      int Index() const { return e.index.block*EDGE_BLOCK_SIZE+e.index.index; }
       //If the edges are indexable 
 
@@ -402,12 +402,12 @@
     public:
       typedef T value_type;
-      void Set(NodeIterator i, const T &t) {map[i.Index()]=t;}
-      T &Get(NodeIterator i) {return map[i.Index()];}
-      T &operator[](NodeIterator i) {return map[i.Index()];}
-
-      void update() { map.resize(G->OldGraph<N,E>::NodeMax());}
-
-      NodeMap(Graph<N,E> &Gr) : map(Gr.OldGraph<N,E>::NodeMax()) { G=&Gr ;}
-      
+      void Put(const NodeIterator i, const T &t) {map[i.Index()]=t;}
+      T Get(const NodeIterator i) const {return map[i.Index()];}
+      T operator[](NodeIterator i) {return map[i.Index()];}
+
+      void update() { map.resize(G->MaxNode());}
+
+      NodeMap() {}
+      void SetG(Graph<N,E> &Gr) { G=&Gr; update();}      
     };
 
@@ -419,16 +419,20 @@
     public:
       typedef T value_type;
-      void Set(NodeIterator i, const T &t) {map[i.Index()]=t;}
-      T &Get(NodeIterator i) {return map[i.Index()];}
+      void Put(const NodeIterator i, const T &t) {map[i.Index()]=t;}
+      T &Get(const NodeIterator i) {return map[i.Index()];}
       T &operator[](NodeIterator i) {return map[i.Index()];}
       
       void update()
-	{ map.resize(Gr.OldGraph<N,E>::edge_block_num*EDGE_BLOCK_SIZE);}
-      
-      EdgeMap(Graph<N,E> &Gr) 
-	:map(Gr.OldGraph<N,E>::edge_block_num*EDGE_BLOCK_SIZE)
-	{ G=&Gr ;}
-      
-    };
+	{ map.resize(G->MaxEdge());}
+      
+      EdgeMap() {}
+      void SetG(Graph<N,E> &Gr) 
+      { G=&Gr ;update();}
+      
+    };
+    
+
+    int MaxNode() { return OldGraph<N,E>::MaxNode();}
+    int MaxEdge() { return ::edge_block_num*EDGE_BLOCK_SIZE;}
     
   };
Index: src/work/bfsdemo.cc
===================================================================
--- src/work/bfsdemo.cc	(revision 6)
+++ src/work/bfsdemo.cc	(revision 8)
@@ -68,4 +68,5 @@
     void Put(const IGraph::NodeIterator &n,const value_type &t) { n->isVis=t; }
     value_type Get(const IGraph::NodeIterator &n) const { return n->isVis; }
+    void SetG(IGraph &G) {}
   } visited;
   struct _tree_map_t {
@@ -73,4 +74,5 @@
     void Put(const IGraph::NodeIterator &n,const value_type &t)
     { cout << t.From().Index() << "->" << t.To().Index() << '\n'; }
+    void SetG(IGraph &G) {}
   } tree;
   do_nothing_map dist;   //node->int (W)
@@ -90,4 +92,5 @@
     void Put(const IGraph::NodeIterator &n,const value_type &t) { n->isVis=t; }
     value_type Get(const IGraph::NodeIterator &n) const { return n->isVis; }
+    void SetG(IGraph &G) {}
   };
   struct tree_map_t {
@@ -95,4 +98,5 @@
     void Put(const IGraph::NodeIterator &n,const value_type &t)
     { cout << t.From().Index() << "->" << t.To().Index() << '\n'; }
+    void SetG(IGraph &G) {}
   };
   typedef do_nothing_map dist_map_t;   //node->int (W)
Index: src/work/bfsdemo2.cc
===================================================================
--- src/work/bfsdemo2.cc	(revision 6)
+++ src/work/bfsdemo2.cc	(revision 8)
@@ -16,5 +16,7 @@
   TestGraph::NodeIterator tn,n2;
   
-  for(int i=1;i<=5000;i++)
+  cout << "Create nodes\n";
+
+  for(int i=1;i<=500;i++)
     {
       *(tn=G.AddNode())=i;
@@ -22,8 +24,13 @@
     }
   
+  cout << "Create Edges\n";
+  
   for(TestGraph::NodeIterator n(G);n.isValid();++n)
-    for(TestGraph::NodeIterator m(G);m.isValid();++m)
+    for(TestGraph::NodeIterator m(G);m.isValid();++m) if(n!=m)
       if(gcd(*n,*m)>1) G.AddEdge(n,m);
   
+  
+  cout << "Run BFS\n";
+
   Bfs<default_bfs_T<TestGraph> > bfs;
 
@@ -33,6 +40,11 @@
 
   for(TestGraph::NodeIterator n(G);n.isValid();++n)
-    cout << Get(bfs.tree_map,n).From() << "->" << Get(bfs.tree_map,n).To()
-	 << '\n';
+    if((*n)!=2)
+      cout << (Get(bfs.dist_map,n)) << '\n';
 
+  for(TestGraph::NodeIterator n(G);n.isValid();++n)
+    if(Get(bfs.dist_map,n))
+      cout << *(Get(bfs.tree_map,n).From()) << "->"
+	   << *(Get(bfs.tree_map,n).To())
+	   << '\n';
 }
