Index: lemon/Makefile.am
===================================================================
--- lemon/Makefile.am	(revision 103)
+++ lemon/Makefile.am	(revision 101)
@@ -8,4 +8,5 @@
 
 lemon_libemon_la_SOURCES = \
+        lemon/arg_parser.cc \
         lemon/base.cc \
         lemon/random.cc
@@ -16,14 +17,18 @@
 
 lemon_HEADERS += \
-        lemon/concept_check.h \
+        lemon/arg_parser.h \
+        lemon/bfs.h \
+        lemon/bin_heap.h \
+        lemon/dfs.h \
+        lemon/dijkstra.h \
         lemon/dim2.h \
 	lemon/error.h \
-	lemon/kruskal.h \
+        lemon/graph_utils.h \
 	lemon/list_graph.h \
 	lemon/maps.h \
 	lemon/math.h \
+	lemon/path.h \
         lemon/random.h \
-        lemon/tolerance.h \
-	lemon/unionfind.h
+        lemon/tolerance.h
 
 bits_HEADERS += \
@@ -35,4 +40,5 @@
         lemon/bits/invalid.h \
 	lemon/bits/map_extender.h \
+	lemon/bits/path_dump.h \
 	lemon/bits/traits.h \
         lemon/bits/utility.h \
@@ -43,4 +49,6 @@
 	lemon/concepts/digraph.h \
 	lemon/concepts/graph.h \
+	lemon/concepts/heap.h \
 	lemon/concepts/maps.h \
+	lemon/concepts/path.h \
 	lemon/concepts/graph_components.h
Index: lemon/arg_parser.cc
===================================================================
--- lemon/arg_parser.cc	(revision 88)
+++ lemon/arg_parser.cc	(revision 88)
@@ -0,0 +1,465 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#include <lemon/arg_parser.h>
+
+namespace lemon {
+
+  void ArgParser::_showHelp(void *p)
+  {
+    (static_cast<ArgParser*>(p))->showHelp();
+    exit(1);
+  }
+
+  ArgParser::ArgParser(int argc, const char **argv) :_argc(argc), _argv(argv),
+                                                     _command_name(argv[0]) {
+    funcOption("-help","Print a short help message",_showHelp,this);
+    synonym("help","-help");
+    synonym("h","-help");
+
+  }
+
+  ArgParser::~ArgParser()
+  {
+    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
+      if(i->second.self_delete)
+	switch(i->second.type) {
+	case BOOL:
+	  delete i->second.bool_p;
+	  break;
+	case STRING:
+	  delete i->second.string_p;
+	  break;
+	case DOUBLE:
+	  delete i->second.double_p;
+	  break;
+	case INTEGER:
+	  delete i->second.int_p;
+	  break;
+	case UNKNOWN:
+	  break;
+	case FUNC:
+	  break;
+	}
+  }
+  
+
+  ArgParser &ArgParser::intOption(const std::string &name,
+			       const std::string &help,
+			       int value, bool obl)
+  {
+    ParData p;
+    p.int_p=new int(value);
+    p.self_delete=true;
+    p.help=help;
+    p.type=INTEGER;
+    p.mandatory=obl;
+    _opts[name]=p;
+    return *this;
+  }
+
+  ArgParser &ArgParser::doubleOption(const std::string &name,
+			       const std::string &help,
+			       double value, bool obl)
+  {
+    ParData p;
+    p.double_p=new double(value);
+    p.self_delete=true;
+    p.help=help;
+    p.type=DOUBLE;
+    p.mandatory=obl;
+    _opts[name]=p;
+    return *this;
+  }
+
+  ArgParser &ArgParser::boolOption(const std::string &name,
+			       const std::string &help,
+			       bool value, bool obl)
+  {
+    ParData p;
+    p.bool_p=new bool(value);
+    p.self_delete=true;
+    p.help=help;
+    p.type=BOOL;
+    p.mandatory=obl;
+    _opts[name]=p;
+    return *this;
+  }
+
+  ArgParser &ArgParser::stringOption(const std::string &name,
+			       const std::string &help,
+			       std::string value, bool obl)
+  {
+    ParData p;
+    p.string_p=new std::string(value);
+    p.self_delete=true;
+    p.help=help;
+    p.type=STRING;
+    p.mandatory=obl;
+    _opts[name]=p;
+    return *this;
+  }
+
+  ArgParser &ArgParser::refOption(const std::string &name,
+			       const std::string &help,
+			       int &ref, bool obl)
+  {
+    ParData p;
+    p.int_p=&ref;
+    p.self_delete=false;
+    p.help=help;
+    p.type=INTEGER;
+    p.mandatory=obl;
+    _opts[name]=p;
+    return *this;
+  }
+
+  ArgParser &ArgParser::refOption(const std::string &name,
+                                  const std::string &help,
+                                  double &ref, bool obl)
+  {
+    ParData p;
+    p.double_p=&ref;
+    p.self_delete=false;
+    p.help=help;
+    p.type=DOUBLE;
+    p.mandatory=obl;
+    _opts[name]=p;
+    return *this;
+  }
+
+  ArgParser &ArgParser::refOption(const std::string &name,
+                                  const std::string &help,
+                                  bool &ref, bool obl)
+  {
+    ParData p;
+    p.bool_p=&ref;
+    p.self_delete=false;
+    p.help=help;
+    p.type=BOOL;
+    p.mandatory=obl;
+    _opts[name]=p;
+
+    ref = false;
+
+    return *this;
+  }
+
+  ArgParser &ArgParser::refOption(const std::string &name,
+			       const std::string &help,
+			       std::string &ref, bool obl)
+  {
+    ParData p;
+    p.string_p=&ref;
+    p.self_delete=false;
+    p.help=help;
+    p.type=STRING;
+    p.mandatory=obl;
+    _opts[name]=p;
+    return *this;
+  }
+
+  ArgParser &ArgParser::funcOption(const std::string &name,
+			       const std::string &help,
+			       void (*func)(void *),void *data)
+  {
+    ParData p;
+    p.func_p.p=func;
+    p.func_p.data=data;
+    p.self_delete=false;
+    p.help=help;
+    p.type=FUNC;
+    p.mandatory=false;
+    _opts[name]=p;
+    return *this;
+  }
+
+  ArgParser &ArgParser::optionGroup(const std::string &group,
+				    const std::string &opt)
+  {
+    Opts::iterator i = _opts.find(opt);
+    LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'");
+    LEMON_ASSERT(!(i->second.ingroup), 
+                 "Option already in option group: '"+opt+"'");
+    GroupData &g=_groups[group];
+    g.opts.push_back(opt);
+    i->second.ingroup=true;
+    return *this;
+  }
+
+  ArgParser &ArgParser::onlyOneGroup(const std::string &group)
+  {
+    GroupData &g=_groups[group];
+    g.only_one=true;
+    return *this;
+  }
+
+  ArgParser &ArgParser::synonym(const std::string &syn,
+				const std::string &opt)
+  {
+    Opts::iterator o = _opts.find(opt);
+    Opts::iterator s = _opts.find(syn);
+    LEMON_ASSERT(o!=_opts.end(), "Unknown option: '"+opt+"'");
+    LEMON_ASSERT(s==_opts.end(), "Option already used: '"+syn+"'");
+    ParData p;
+    p.help=opt;
+    p.mandatory=false;
+    p.syn=true;
+    _opts[syn]=p;
+    o->second.has_syn=true;
+    return *this;
+  }
+
+  ArgParser &ArgParser::mandatoryGroup(const std::string &group)
+  {
+    GroupData &g=_groups[group];
+    g.mandatory=true;
+    return *this;
+  }
+
+  ArgParser &ArgParser::other(const std::string &name,
+			      const std::string &help)
+  {
+    _others_help.push_back(OtherArg(name,help));
+    return *this;
+  }
+
+  void ArgParser::show(std::ostream &os,Opts::iterator i)
+  {
+    os << "-" << i->first;
+    if(i->second.has_syn)
+      for(Opts::iterator j=_opts.begin();j!=_opts.end();++j)
+	if(j->second.syn&&j->second.help==i->first)
+	  os << "|-" << j->first;
+    switch(i->second.type) {
+    case STRING:
+      os << " str";
+      break;
+    case INTEGER:
+      os << " int";
+      break;
+    case DOUBLE:
+      os << " num";
+      break;
+    default:
+      break;
+    }
+  }
+
+  void ArgParser::show(std::ostream &os,Groups::iterator i)
+  {
+    GroupData::Opts::iterator o=i->second.opts.begin();
+    while(o!=i->second.opts.end()) {
+      show(os,_opts.find(*o));
+      ++o;
+      if(o!=i->second.opts.end()) os<<'|';
+    }
+  }
+    
+  void ArgParser::showHelp(Opts::iterator i)
+  {
+    if(i->second.help.size()==0||i->second.syn) return;
+    std::cerr << "  ";
+    show(std::cerr,i);
+    std::cerr << std::endl;
+    std::cerr << "     " << i->second.help << std::endl;
+  }
+  void ArgParser::showHelp(std::vector<ArgParser::OtherArg>::iterator i)
+  {
+    if(i->help.size()==0) return;
+    std::cerr << "  " << i->name << std::endl
+	      << "     " << i->help << std::endl;
+  }
+    
+  void ArgParser::shortHelp()
+  {
+    const unsigned int LINE_LEN=77;
+    const std::string indent("    ");
+    std::cerr << "Usage:\n  " << _command_name;
+    int pos=_command_name.size()+2;
+    for(Groups::iterator g=_groups.begin();g!=_groups.end();++g) {
+      std::ostringstream cstr;
+      cstr << ' ';
+      if(!g->second.mandatory) cstr << '[';
+      show(cstr,g);
+      if(!g->second.mandatory) cstr << ']';
+      if(pos+cstr.str().size()>LINE_LEN) {
+	std::cerr << std::endl << indent;
+	pos=indent.size();
+      }
+      std::cerr << cstr.str();
+      pos+=cstr.str().size();
+    }
+    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
+      if(!i->second.ingroup&&!i->second.syn) {
+	std::ostringstream cstr;
+	cstr << ' ';
+	if(!i->second.mandatory) cstr << '[';
+	show(cstr,i);
+	if(!i->second.mandatory) cstr << ']';
+	if(pos+cstr.str().size()>LINE_LEN) {
+	  std::cerr << std::endl << indent;
+	  pos=indent.size();
+	}
+	std::cerr << cstr.str();
+	pos+=cstr.str().size();
+      }
+    for(std::vector<OtherArg>::iterator i=_others_help.begin();
+	i!=_others_help.end();++i)
+      {
+	std::ostringstream cstr;
+	cstr << ' ' << i->name;
+      
+	if(pos+cstr.str().size()>LINE_LEN) {
+	  std::cerr << std::endl << indent;
+	  pos=indent.size();
+	}
+	std::cerr << cstr.str();
+	pos+=cstr.str().size();
+      }
+    std::cerr << std::endl;
+  }
+    
+  void ArgParser::showHelp()
+  {
+    shortHelp();
+    std::cerr << "Where:\n";
+    for(std::vector<OtherArg>::iterator i=_others_help.begin();
+	i!=_others_help.end();++i) showHelp(i);
+    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i);
+    exit(1);
+  }
+    
+      
+  void ArgParser::unknownOpt(std::string arg) 
+  {
+    std::cerr << "\nUnknown option: " << arg << "\n";
+    std::cerr << "\nType '" << _command_name <<
+      " --help' to obtain a short summary on the usage.\n\n";
+    exit(1);
+  }
+    
+  void ArgParser::requiresValue(std::string arg, OptType t) 
+  {
+    std::cerr << "Argument '" << arg << "' requires a";
+    switch(t) {
+    case STRING:
+      std::cerr << " string";
+      break;
+    case INTEGER:
+      std::cerr << "n integer";
+      break;
+    case DOUBLE:
+      std::cerr << " floating point";
+      break;
+    default:
+      break;
+    }
+    std::cerr << " value\n\n";
+    showHelp();
+  }
+    
+
+  void ArgParser::checkMandatories()
+  {
+    bool ok=true;
+    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
+      if(i->second.mandatory&&!i->second.set) 
+	{
+	  if(ok)
+	    std::cerr << _command_name 
+		      << ": The following mandatory arguments are missing.\n";
+	  ok=false;
+	  showHelp(i);
+	}
+    for(Groups::iterator i=_groups.begin();i!=_groups.end();++i)
+      if(i->second.mandatory||i->second.only_one)
+	{
+	  int set=0;
+	  for(GroupData::Opts::iterator o=i->second.opts.begin();
+	      o!=i->second.opts.end();++o)
+	    if(_opts.find(*o)->second.set) ++set;
+	  if(i->second.mandatory&&!set) {
+	    std::cerr << _command_name 
+		      << ": At least one of the following arguments is mandatory.\n";
+	    ok=false;
+	    for(GroupData::Opts::iterator o=i->second.opts.begin();
+		o!=i->second.opts.end();++o)
+	      showHelp(_opts.find(*o));
+	  }
+	  if(i->second.only_one&&set>1) {
+	    std::cerr << _command_name 
+		      << ": At most one of the following arguments can be given.\n";
+	    ok=false;
+	    for(GroupData::Opts::iterator o=i->second.opts.begin();
+		o!=i->second.opts.end();++o)
+	      showHelp(_opts.find(*o));
+	  }
+	}
+    if(!ok) {
+      std::cerr << "\nType '" << _command_name <<
+	" --help' to obtain a short summary on the usage.\n\n";
+      exit(1);
+    }
+  }
+
+  ArgParser &ArgParser::parse()
+  {
+    for(int ar=1; ar<_argc; ++ar) {
+      std::string arg(_argv[ar]);
+      if (arg[0] != '-' || arg.size() == 1) {
+	_file_args.push_back(arg);
+      }
+      else {
+	Opts::iterator i = _opts.find(arg.substr(1));
+	if(i==_opts.end()) unknownOpt(arg);
+	else {
+	  if(i->second.syn) i=_opts.find(i->second.help);
+	  ParData &p(i->second);
+	  if (p.type==BOOL) *p.bool_p=true;
+	  else if (p.type==FUNC) p.func_p.p(p.func_p.data);
+	  else if(++ar==_argc) requiresValue(arg, p.type);
+	  else {
+	    std::string val(_argv[ar]);
+	    std::istringstream vals(val);
+	    switch(p.type) {
+	    case STRING:
+	      *p.string_p=val;
+	      break;
+	    case INTEGER:
+	      vals >> *p.int_p;
+	      break;
+	    case DOUBLE:
+	      vals >> *p.double_p;
+	      break;
+	    default:
+	      break;
+	    }
+	    if(p.type!=STRING&&(!vals||!vals.eof()))
+	      requiresValue(arg, p.type);
+	  }
+	  p.set = true;
+	}
+      }
+    }
+    checkMandatories();
+
+    return *this;
+  }  
+
+}
Index: lemon/arg_parser.h
===================================================================
--- lemon/arg_parser.h	(revision 95)
+++ lemon/arg_parser.h	(revision 95)
@@ -0,0 +1,369 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_ARG_PARSER
+#define LEMON_ARG_PARSER
+
+#include <vector>
+#include <map>
+#include <list>
+#include <string>
+#include <iostream>
+#include <sstream>
+#include <algorithm>
+#include <lemon/error.h>
+
+///\ingroup misc
+///\file
+///\brief A tool to parse command line arguments.
+
+namespace lemon {
+
+  ///Command line arguments parser
+
+  ///\ingroup misc
+  ///Command line arguments parser.
+  ///
+  ///For a complete example see the \ref arg_parser_demo.cc demo file.
+  class ArgParser {
+    
+    static void _showHelp(void *p);
+  protected:
+    
+    int _argc;
+    const char **_argv;
+    
+    enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 };
+    
+    class ParData {
+    public:
+      union {
+	bool *bool_p;
+	int *int_p;
+	double *double_p;
+	std::string *string_p;
+	struct {
+	  void (*p)(void *);
+	  void *data;
+	} func_p;
+	  
+      };
+      std::string help;
+      bool mandatory;
+      OptType type;
+      bool set;
+      bool ingroup;
+      bool has_syn;
+      bool syn;
+      bool self_delete;
+      ParData() : mandatory(false), type(UNKNOWN), set(false), ingroup(false),
+		  has_syn(false), syn(false), self_delete(false) {}
+    };
+
+    typedef std::map<std::string,ParData> Opts;
+    Opts _opts;
+
+    class GroupData 
+    {
+    public:
+      typedef std::list<std::string> Opts;
+      Opts opts;
+      bool only_one;
+      bool mandatory;
+      GroupData() :only_one(false), mandatory(false) {}
+    };
+      
+    typedef std::map<std::string,GroupData> Groups;
+    Groups _groups;
+
+    struct OtherArg
+    {
+      std::string name;
+      std::string help;
+      OtherArg(std::string n, std::string h) :name(n), help(h) {}
+
+    };
+      
+    std::vector<OtherArg> _others_help;
+    std::vector<std::string> _file_args;
+    std::string _command_name;
+
+    
+  private:
+    //Bind a function to an option.
+
+    //\param name The name of the option. The leading '-' must be omitted.
+    //\param help A help string.
+    //\retval func The function to be called when the option is given. It
+    //  must be of type "void f(void *)"
+    //\param data Data to be passed to \c func
+    ArgParser &funcOption(const std::string &name,
+		    const std::string &help,
+		    void (*func)(void *),void *data);
+    
+  public:
+
+    ///\e
+    ArgParser(int argc, const char **argv);
+
+    ~ArgParser();
+
+    ///Add a new integer type option
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\param value A default value for the option.
+    ///\param obl Indicate if the option is mandatory.
+    ArgParser &intOption(const std::string &name,
+		    const std::string &help,
+		    int value=0, bool obl=false);
+
+    ///Add a new floating point type option
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\param value A default value for the option.
+    ///\param obl Indicate if the option is mandatory.
+    ArgParser &doubleOption(const std::string &name,
+		      const std::string &help,
+		      double value=0, bool obl=false);
+
+    ///Add a new bool type option
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\param value A default value for the option.
+    ///\param obl Indicate if the option is mandatory.
+    ///\note A mandatory bool obtion is of very little use.
+    ArgParser &boolOption(const std::string &name,
+		      const std::string &help,
+		      bool value=false, bool obl=false);
+
+    ///Add a new string type option
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\param value A default value for the option.
+    ///\param obl Indicate if the option is mandatory.
+    ArgParser &stringOption(const std::string &name,
+		      const std::string &help,
+		      std::string value="", bool obl=false);
+
+    ///\name Options with external storage
+    ///Using this functions, the value of the option will be directly written
+    ///into a variable once the option appears in the command line.
+
+    ///@{
+
+    ///Add a new integer type option with a storage reference
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\param obl Indicate if the option is mandatory.
+    ///\retval ref The value of the argument will be written to this variable.
+    ArgParser &refOption(const std::string &name,
+		    const std::string &help,
+		    int &ref, bool obl=false);
+
+    ///Add a new floating type option with a storage reference
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\param obl Indicate if the option is mandatory.
+    ///\retval ref The value of the argument will be written to this variable.
+    ArgParser &refOption(const std::string &name,
+		      const std::string &help,
+		      double &ref, bool obl=false);
+
+    ///Add a new bool type option with a storage reference
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\param obl Indicate if the option is mandatory.
+    ///\retval ref The value of the argument will be written to this variable.
+    ///\note A mandatory bool obtion is of very little use.
+    ArgParser &refOption(const std::string &name,
+		      const std::string &help,
+		      bool &ref, bool obl=false);
+
+    ///Add a new string type option with a storage reference
+
+    ///\param name The name of the option. The leading '-' must be omitted.
+    ///\param help A help string.
+    ///\param obl Indicate if the option is mandatory.
+    ///\retval ref The value of the argument will be written to this variable.
+    ArgParser &refOption(const std::string &name,
+		      const std::string &help,
+		      std::string &ref, bool obl=false);
+    
+    ///@}
+
+    ///\name Option Groups and Synonyms
+    ///
+    
+    ///@{
+
+    ///Boundle some options into a group
+
+    /// You can group some option by calling this function repeatedly for each
+    /// option to be grouped with the same groupname.
+    ///\param group The group name.
+    ///\param opt The option name.
+    ArgParser &optionGroup(const std::string &group,
+			   const std::string &opt);
+
+    ///Make the members of a group exclusive
+
+    ///If you call this function for a group, than at most one of them can be
+    ///given at the same time
+    ArgParser &onlyOneGroup(const std::string &group);
+  
+    ///Make a group mandatory
+
+    ///Using this function, at least one of the members of \c group
+    ///must be given.
+    ArgParser &mandatoryGroup(const std::string &group);
+    
+    ///Create synonym to an option
+
+    ///With this function you can create a synonym \c syn of the
+    ///option \c opt.
+    ArgParser &synonym(const std::string &syn,
+			   const std::string &opt);
+    
+    ///@}
+
+    ///Give help string for non-parsed arguments.
+
+    ///With this function you can give help string for non-parsed arguments.
+    ///The parameter \c name will be printed in the short usage line, while
+    ///\c help gives a more detailed description.
+    ArgParser &other(const std::string &name,
+		     const std::string &help="");
+    
+    ///Give back the non-option type arguments.
+
+    ///Give back a reference to a vector consisting of the program arguments
+    ///not starting with a '-' character.
+    std::vector<std::string> &files() { return _file_args; }
+
+    ///Give back the command name (the 0th argument)
+    const std::string &commandName() { return _command_name; }
+
+    void show(std::ostream &os,Opts::iterator i);
+    void show(std::ostream &os,Groups::iterator i);
+    void showHelp(Opts::iterator i);
+    void showHelp(std::vector<OtherArg>::iterator i);
+    void shortHelp();
+    void showHelp();
+
+    void unknownOpt(std::string arg);
+
+    void requiresValue(std::string arg, OptType t);
+    void checkMandatories();
+    
+    ///Start the parsing process
+    ArgParser &parse();
+
+    /// Synonym for parse()
+    ArgParser &run() 
+    {
+      return parse();
+    }
+    
+    ///Check if an opion has been given to the command.
+    bool given(std::string op) 
+    {
+      Opts::iterator i = _opts.find(op);
+      return i!=_opts.end()?i->second.set:false;
+    }
+
+
+    ///Magic type for operator[]
+    
+    ///This is the type of the return value of ArgParser::operator[]().
+    ///It automatically converts to \c int, \c double, \c bool or
+    ///\c std::string if the type of the option matches, otherwise it
+    ///throws an exception (i.e. it performs runtime type checking).
+    class RefType 
+    {
+      ArgParser &_parser;
+      std::string _name;
+    public:
+      ///\e
+      RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
+      ///\e
+      operator bool() 
+      {
+	Opts::iterator i = _parser._opts.find(_name);
+	LEMON_ASSERT(i!=_parser._opts.end(),
+		     std::string()+"Unkown option: '"+_name+"'");
+	LEMON_ASSERT(i->second.type==ArgParser::BOOL,
+		     std::string()+"'"+_name+"' is a bool option");
+	return *(i->second.bool_p);
+      }
+      ///\e
+      operator std::string()
+      {
+	Opts::iterator i = _parser._opts.find(_name);
+	LEMON_ASSERT(i!=_parser._opts.end(),
+		     std::string()+"Unkown option: '"+_name+"'");
+	LEMON_ASSERT(i->second.type==ArgParser::STRING,
+		     std::string()+"'"+_name+"' is a string option");
+	return *(i->second.string_p);
+      }
+      ///\e
+      operator double() 
+      {
+	Opts::iterator i = _parser._opts.find(_name);
+	LEMON_ASSERT(i!=_parser._opts.end(),
+		     std::string()+"Unkown option: '"+_name+"'");
+	LEMON_ASSERT(i->second.type==ArgParser::DOUBLE ||
+		     i->second.type==ArgParser::INTEGER,
+		     std::string()+"'"+_name+"' is a floating point option");
+	return i->second.type==ArgParser::DOUBLE ?
+	  *(i->second.double_p) : *(i->second.int_p);
+      }
+      ///\e
+      operator int() 
+      {
+	Opts::iterator i = _parser._opts.find(_name);
+	LEMON_ASSERT(i!=_parser._opts.end(),
+		     std::string()+"Unkown option: '"+_name+"'");
+	LEMON_ASSERT(i->second.type==ArgParser::INTEGER,
+		     std::string()+"'"+_name+"' is an integer option");
+	return *(i->second.int_p);
+      }
+
+    };
+
+    ///Give back the value of an option
+    
+    ///Give back the value of an option.
+    ///\sa RefType
+    RefType operator[](const std::string &n)
+    {
+      return RefType(*this, n);
+    }    
+ 
+  };
+}
+
+    
+
+#endif // LEMON_MAIN_PARAMS
Index: lemon/bfs.h
===================================================================
--- lemon/bfs.h	(revision 100)
+++ lemon/bfs.h	(revision 100)
@@ -0,0 +1,1597 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_BFS_H
+#define LEMON_BFS_H
+
+///\ingroup search
+///\file
+///\brief Bfs algorithm.
+
+#include <lemon/list_graph.h>
+#include <lemon/graph_utils.h>
+#include <lemon/bits/path_dump.h>
+#include <lemon/bits/invalid.h>
+#include <lemon/error.h>
+#include <lemon/maps.h>
+
+namespace lemon {
+
+
+  
+  ///Default traits class of Bfs class.
+
+  ///Default traits class of Bfs class.
+  ///\param GR Digraph type.
+  template<class GR>
+  struct BfsDefaultTraits
+  {
+    ///The digraph type the algorithm runs on. 
+    typedef GR Digraph;
+    ///\brief The type of the map that stores the last
+    ///arcs of the shortest paths.
+    /// 
+    ///The type of the map that stores the last
+    ///arcs of the shortest paths.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
+    ///Instantiates a PredMap.
+ 
+    ///This function instantiates a \ref PredMap. 
+    ///\param G is the digraph, to which we would like to define the PredMap.
+    ///\todo The digraph alone may be insufficient to initialize
+    static PredMap *createPredMap(const GR &G) 
+    {
+      return new PredMap(G);
+    }
+    ///The type of the map that indicates which nodes are processed.
+ 
+    ///The type of the map that indicates which nodes are processed.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
+    ///Instantiates a ProcessedMap.
+ 
+    ///This function instantiates a \ref ProcessedMap. 
+    ///\param g is the digraph, to which
+    ///we would like to define the \ref ProcessedMap
+#ifdef DOXYGEN
+    static ProcessedMap *createProcessedMap(const GR &g)
+#else
+    static ProcessedMap *createProcessedMap(const GR &)
+#endif
+    {
+      return new ProcessedMap();
+    }
+    ///The type of the map that indicates which nodes are reached.
+ 
+    ///The type of the map that indicates which nodes are reached.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef typename Digraph::template NodeMap<bool> ReachedMap;
+    ///Instantiates a ReachedMap.
+ 
+    ///This function instantiates a \ref ReachedMap. 
+    ///\param G is the digraph, to which
+    ///we would like to define the \ref ReachedMap.
+    static ReachedMap *createReachedMap(const GR &G)
+    {
+      return new ReachedMap(G);
+    }
+    ///The type of the map that stores the dists of the nodes.
+ 
+    ///The type of the map that stores the dists of the nodes.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef typename Digraph::template NodeMap<int> DistMap;
+    ///Instantiates a DistMap.
+ 
+    ///This function instantiates a \ref DistMap. 
+    ///\param G is the digraph, to which we would like to define the \ref DistMap
+    static DistMap *createDistMap(const GR &G)
+    {
+      return new DistMap(G);
+    }
+  };
+  
+  ///%BFS algorithm class.
+  
+  ///\ingroup search
+  ///This class provides an efficient implementation of the %BFS algorithm.
+  ///
+  ///\param GR The digraph type the algorithm runs on. The default value is
+  ///\ref ListDigraph. The value of GR is not used directly by Bfs, it
+  ///is only passed to \ref BfsDefaultTraits.
+  ///\param TR Traits class to set various data types used by the algorithm.
+  ///The default traits class is
+  ///\ref BfsDefaultTraits "BfsDefaultTraits<GR>".
+  ///See \ref BfsDefaultTraits for the documentation of
+  ///a Bfs traits class.
+  ///
+  ///\author Alpar Juttner
+
+#ifdef DOXYGEN
+  template <typename GR,
+	    typename TR>
+#else
+  template <typename GR=ListDigraph,
+	    typename TR=BfsDefaultTraits<GR> >
+#endif
+  class Bfs {
+  public:
+    /**
+     * \brief \ref Exception for uninitialized parameters.
+     *
+     * This error represents problems in the initialization
+     * of the parameters of the algorithms.
+     */
+    class UninitializedParameter : public lemon::UninitializedParameter {
+    public:
+      virtual const char* what() const throw() {
+	return "lemon::Bfs::UninitializedParameter";
+      }
+    };
+
+    typedef TR Traits;
+    ///The type of the underlying digraph.
+    typedef typename TR::Digraph Digraph;
+    
+    ///\brief The type of the map that stores the last
+    ///arcs of the shortest paths.
+    typedef typename TR::PredMap PredMap;
+    ///The type of the map indicating which nodes are reached.
+    typedef typename TR::ReachedMap ReachedMap;
+    ///The type of the map indicating which nodes are processed.
+    typedef typename TR::ProcessedMap ProcessedMap;
+    ///The type of the map that stores the dists of the nodes.
+    typedef typename TR::DistMap DistMap;
+  private:
+
+    typedef typename Digraph::Node Node;
+    typedef typename Digraph::NodeIt NodeIt;
+    typedef typename Digraph::Arc Arc;
+    typedef typename Digraph::OutArcIt OutArcIt;
+
+    /// Pointer to the underlying digraph.
+    const Digraph *G;
+    ///Pointer to the map of predecessors arcs.
+    PredMap *_pred;
+    ///Indicates if \ref _pred is locally allocated (\c true) or not.
+    bool local_pred;
+    ///Pointer to the map of distances.
+    DistMap *_dist;
+    ///Indicates if \ref _dist is locally allocated (\c true) or not.
+    bool local_dist;
+    ///Pointer to the map of reached status of the nodes.
+    ReachedMap *_reached;
+    ///Indicates if \ref _reached is locally allocated (\c true) or not.
+    bool local_reached;
+    ///Pointer to the map of processed status of the nodes.
+    ProcessedMap *_processed;
+    ///Indicates if \ref _processed is locally allocated (\c true) or not.
+    bool local_processed;
+
+    std::vector<typename Digraph::Node> _queue;
+    int _queue_head,_queue_tail,_queue_next_dist;
+    int _curr_dist;
+
+    ///Creates the maps if necessary.
+    
+    ///\todo Better memory allocation (instead of new).
+    void create_maps() 
+    {
+      if(!_pred) {
+	local_pred = true;
+	_pred = Traits::createPredMap(*G);
+      }
+      if(!_dist) {
+	local_dist = true;
+	_dist = Traits::createDistMap(*G);
+      }
+      if(!_reached) {
+	local_reached = true;
+	_reached = Traits::createReachedMap(*G);
+      }
+      if(!_processed) {
+	local_processed = true;
+	_processed = Traits::createProcessedMap(*G);
+      }
+    }
+
+  protected:
+    
+    Bfs() {}
+    
+  public:
+ 
+    typedef Bfs Create;
+
+    ///\name Named template parameters
+
+    ///@{
+
+    template <class T>
+    struct DefPredMapTraits : public Traits {
+      typedef T PredMap;
+      static PredMap *createPredMap(const Digraph &) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///PredMap type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting PredMap type
+    ///
+    template <class T>
+    struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > { 
+      typedef Bfs< Digraph, DefPredMapTraits<T> > Create;
+    };
+    
+    template <class T>
+    struct DefDistMapTraits : public Traits {
+      typedef T DistMap;
+      static DistMap *createDistMap(const Digraph &) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///DistMap type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting DistMap type
+    ///
+    template <class T>
+    struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > { 
+      typedef Bfs< Digraph, DefDistMapTraits<T> > Create;
+    };
+    
+    template <class T>
+    struct DefReachedMapTraits : public Traits {
+      typedef T ReachedMap;
+      static ReachedMap *createReachedMap(const Digraph &) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///ReachedMap type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting ReachedMap type
+    ///
+    template <class T>
+    struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > { 
+      typedef Bfs< Digraph, DefReachedMapTraits<T> > Create;
+    };
+    
+    template <class T>
+    struct DefProcessedMapTraits : public Traits {
+      typedef T ProcessedMap;
+      static ProcessedMap *createProcessedMap(const Digraph &) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///ProcessedMap type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
+    ///
+    template <class T>
+    struct DefProcessedMap : public Bfs< Digraph, DefProcessedMapTraits<T> > {
+      typedef Bfs< Digraph, DefProcessedMapTraits<T> > Create;
+    };
+    
+    struct DefDigraphProcessedMapTraits : public Traits {
+      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
+      static ProcessedMap *createProcessedMap(const Digraph &G) 
+      {
+	return new ProcessedMap(G);
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter"
+    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
+    ///
+    ///\ref named-templ-param "Named parameter"
+    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
+    ///If you don't set it explicitly, it will be automatically allocated.
+    template <class T>
+    struct DefProcessedMapToBeDefaultMap :
+      public Bfs< Digraph, DefDigraphProcessedMapTraits> { 
+      typedef Bfs< Digraph, DefDigraphProcessedMapTraits> Create;
+    };
+    
+    ///@}
+
+  public:      
+    
+    ///Constructor.
+    
+    ///\param _G the digraph the algorithm will run on.
+    ///
+    Bfs(const Digraph& _G) :
+      G(&_G),
+      _pred(NULL), local_pred(false),
+      _dist(NULL), local_dist(false),
+      _reached(NULL), local_reached(false),
+      _processed(NULL), local_processed(false)
+    { }
+    
+    ///Destructor.
+    ~Bfs() 
+    {
+      if(local_pred) delete _pred;
+      if(local_dist) delete _dist;
+      if(local_reached) delete _reached;
+      if(local_processed) delete _processed;
+    }
+
+    ///Sets the map storing the predecessor arcs.
+
+    ///Sets the map storing the predecessor arcs.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destructor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Bfs &predMap(PredMap &m) 
+    {
+      if(local_pred) {
+	delete _pred;
+	local_pred=false;
+      }
+      _pred = &m;
+      return *this;
+    }
+
+    ///Sets the map indicating the reached nodes.
+
+    ///Sets the map indicating the reached nodes.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destructor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Bfs &reachedMap(ReachedMap &m) 
+    {
+      if(local_reached) {
+	delete _reached;
+	local_reached=false;
+      }
+      _reached = &m;
+      return *this;
+    }
+
+    ///Sets the map indicating the processed nodes.
+
+    ///Sets the map indicating the processed nodes.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destructor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Bfs &processedMap(ProcessedMap &m) 
+    {
+      if(local_processed) {
+	delete _processed;
+	local_processed=false;
+      }
+      _processed = &m;
+      return *this;
+    }
+
+    ///Sets the map storing the distances calculated by the algorithm.
+
+    ///Sets the map storing the distances calculated by the algorithm.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destructor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Bfs &distMap(DistMap &m) 
+    {
+      if(local_dist) {
+	delete _dist;
+	local_dist=false;
+      }
+      _dist = &m;
+      return *this;
+    }
+
+  public:
+    ///\name Execution control
+    ///The simplest way to execute the algorithm is to use
+    ///one of the member functions called \c run(...).
+    ///\n
+    ///If you need more control on the execution,
+    ///first you must call \ref init(), then you can add several source nodes
+    ///with \ref addSource().
+    ///Finally \ref start() will perform the actual path
+    ///computation.
+
+    ///@{
+
+    ///\brief Initializes the internal data structures.
+    ///
+    ///Initializes the internal data structures.
+    ///
+    void init()
+    {
+      create_maps();
+      _queue.resize(countNodes(*G));
+      _queue_head=_queue_tail=0;
+      _curr_dist=1;
+      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
+	_pred->set(u,INVALID);
+	_reached->set(u,false);
+	_processed->set(u,false);
+      }
+    }
+    
+    ///Adds a new source node.
+
+    ///Adds a new source node to the set of nodes to be processed.
+    ///
+    void addSource(Node s)
+    {
+      if(!(*_reached)[s])
+	{
+	  _reached->set(s,true);
+	  _pred->set(s,INVALID);
+	  _dist->set(s,0);
+	  _queue[_queue_head++]=s;
+	  _queue_next_dist=_queue_head;
+	}
+    }
+    
+    ///Processes the next node.
+
+    ///Processes the next node.
+    ///
+    ///\return The processed node.
+    ///
+    ///\warning The queue must not be empty!
+    Node processNextNode()
+    {
+      if(_queue_tail==_queue_next_dist) {
+	_curr_dist++;
+	_queue_next_dist=_queue_head;
+      }
+      Node n=_queue[_queue_tail++];
+      _processed->set(n,true);
+      Node m;
+      for(OutArcIt e(*G,n);e!=INVALID;++e)
+	if(!(*_reached)[m=G->target(e)]) {
+	  _queue[_queue_head++]=m;
+	  _reached->set(m,true);
+	  _pred->set(m,e);
+	  _dist->set(m,_curr_dist);
+	}
+      return n;
+    }
+
+    ///Processes the next node.
+
+    ///Processes the next node. And checks that the given target node
+    ///is reached. If the target node is reachable from the processed
+    ///node then the reached parameter will be set true. The reached
+    ///parameter should be initially false.
+    ///
+    ///\param target The target node.
+    ///\retval reach Indicates that the target node is reached.
+    ///\return The processed node.
+    ///
+    ///\warning The queue must not be empty!
+    Node processNextNode(Node target, bool& reach)
+    {
+      if(_queue_tail==_queue_next_dist) {
+	_curr_dist++;
+	_queue_next_dist=_queue_head;
+      }
+      Node n=_queue[_queue_tail++];
+      _processed->set(n,true);
+      Node m;
+      for(OutArcIt e(*G,n);e!=INVALID;++e)
+	if(!(*_reached)[m=G->target(e)]) {
+	  _queue[_queue_head++]=m;
+	  _reached->set(m,true);
+	  _pred->set(m,e);
+	  _dist->set(m,_curr_dist);
+          reach = reach || (target == m);
+	}
+      return n;
+    }
+
+    ///Processes the next node.
+
+    ///Processes the next node. And checks that at least one of
+    ///reached node has true value in the \c nm node map. If one node
+    ///with true value is reachable from the processed node then the
+    ///rnode parameter will be set to the first of such nodes.
+    ///
+    ///\param nm The node map of possible targets.
+    ///\retval rnode The reached target node.
+    ///\return The processed node.
+    ///
+    ///\warning The queue must not be empty!
+    template<class NM>
+    Node processNextNode(const NM& nm, Node& rnode)
+    {
+      if(_queue_tail==_queue_next_dist) {
+	_curr_dist++;
+	_queue_next_dist=_queue_head;
+      }
+      Node n=_queue[_queue_tail++];
+      _processed->set(n,true);
+      Node m;
+      for(OutArcIt e(*G,n);e!=INVALID;++e)
+	if(!(*_reached)[m=G->target(e)]) {
+	  _queue[_queue_head++]=m;
+	  _reached->set(m,true);
+	  _pred->set(m,e);
+	  _dist->set(m,_curr_dist);
+	  if (nm[m] && rnode == INVALID) rnode = m;
+	}
+      return n;
+    }
+      
+    ///Next node to be processed.
+
+    ///Next node to be processed.
+    ///
+    ///\return The next node to be processed or INVALID if the queue is
+    /// empty.
+    Node nextNode()
+    { 
+      return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID;
+    }
+ 
+    ///\brief Returns \c false if there are nodes
+    ///to be processed in the queue
+    ///
+    ///Returns \c false if there are nodes
+    ///to be processed in the queue
+    bool emptyQueue() { return _queue_tail==_queue_head; }
+    ///Returns the number of the nodes to be processed.
+    
+    ///Returns the number of the nodes to be processed in the queue.
+    int queueSize() { return _queue_head-_queue_tail; }
+    
+    ///Executes the algorithm.
+
+    ///Executes the algorithm.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///This method runs the %BFS algorithm from the root node(s)
+    ///in order to
+    ///compute the
+    ///shortest path to each node. The algorithm computes
+    ///- The shortest path tree.
+    ///- The distance of each node from the root(s).
+    void start()
+    {
+      while ( !emptyQueue() ) processNextNode();
+    }
+    
+    ///Executes the algorithm until \c dest is reached.
+
+    ///Executes the algorithm until \c dest is reached.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///This method runs the %BFS algorithm from the root node(s)
+    ///in order to compute the shortest path to \c dest.
+    ///The algorithm computes
+    ///- The shortest path to \c  dest.
+    ///- The distance of \c dest from the root(s).
+    void start(Node dest)
+    {
+      bool reach = false;
+      while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
+    }
+    
+    ///Executes the algorithm until a condition is met.
+
+    ///Executes the algorithm until a condition is met.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///\param nm must be a bool (or convertible) node map. The
+    ///algorithm will stop when it reaches a node \c v with
+    /// <tt>nm[v]</tt> true.
+    ///
+    ///\return The reached node \c v with <tt>nm[v]</tt> true or
+    ///\c INVALID if no such node was found.
+    template<class NM>
+    Node start(const NM &nm)
+    {
+      Node rnode = INVALID;
+      while ( !emptyQueue() && rnode == INVALID ) {
+	processNextNode(nm, rnode);
+      }
+      return rnode;
+    }
+    
+    ///Runs %BFS algorithm from node \c s.
+    
+    ///This method runs the %BFS algorithm from a root node \c s
+    ///in order to
+    ///compute the
+    ///shortest path to each node. The algorithm computes
+    ///- The shortest path tree.
+    ///- The distance of each node from the root.
+    ///
+    ///\note b.run(s) is just a shortcut of the following code.
+    ///\code
+    ///  b.init();
+    ///  b.addSource(s);
+    ///  b.start();
+    ///\endcode
+    void run(Node s) {
+      init();
+      addSource(s);
+      start();
+    }
+    
+    ///Finds the shortest path between \c s and \c t.
+    
+    ///Finds the shortest path between \c s and \c t.
+    ///
+    ///\return The length of the shortest s---t path if there exists one,
+    ///0 otherwise.
+    ///\note Apart from the return value, b.run(s) is
+    ///just a shortcut of the following code.
+    ///\code
+    ///  b.init();
+    ///  b.addSource(s);
+    ///  b.start(t);
+    ///\endcode
+    int run(Node s,Node t) {
+      init();
+      addSource(s);
+      start(t);
+      return reached(t) ? _curr_dist : 0;
+    }
+    
+    ///@}
+
+    ///\name Query Functions
+    ///The result of the %BFS algorithm can be obtained using these
+    ///functions.\n
+    ///Before the use of these functions,
+    ///either run() or start() must be calleb.
+    
+    ///@{
+
+    typedef PredMapPath<Digraph, PredMap> Path;
+
+    ///Gives back the shortest path.
+    
+    ///Gives back the shortest path.
+    ///\pre The \c t should be reachable from the source.
+    Path path(Node t) 
+    {
+      return Path(*G, *_pred, t);
+    }
+
+    ///The distance of a node from the root(s).
+
+    ///Returns the distance of a node from the root(s).
+    ///\pre \ref run() must be called before using this function.
+    ///\warning If node \c v in unreachable from the root(s) the return value
+    ///of this function is undefined.
+    int dist(Node v) const { return (*_dist)[v]; }
+
+    ///Returns the 'previous arc' of the shortest path tree.
+
+    ///For a node \c v it returns the 'previous arc'
+    ///of the shortest path tree,
+    ///i.e. it returns the last arc of a shortest path from the root(s) to \c
+    ///v. It is \ref INVALID
+    ///if \c v is unreachable from the root(s) or \c v is a root. The
+    ///shortest path tree used here is equal to the shortest path tree used in
+    ///\ref predNode().
+    ///\pre Either \ref run() or \ref start() must be called before using
+    ///this function.
+    Arc predArc(Node v) const { return (*_pred)[v];}
+
+    ///Returns the 'previous node' of the shortest path tree.
+
+    ///For a node \c v it returns the 'previous node'
+    ///of the shortest path tree,
+    ///i.e. it returns the last but one node from a shortest path from the
+    ///root(a) to \c /v.
+    ///It is INVALID if \c v is unreachable from the root(s) or
+    ///if \c v itself a root.
+    ///The shortest path tree used here is equal to the shortest path
+    ///tree used in \ref predArc().
+    ///\pre Either \ref run() or \ref start() must be called before
+    ///using this function.
+    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
+				  G->source((*_pred)[v]); }
+    
+    ///Returns a reference to the NodeMap of distances.
+
+    ///Returns a reference to the NodeMap of distances.
+    ///\pre Either \ref run() or \ref init() must
+    ///be called before using this function.
+    const DistMap &distMap() const { return *_dist;}
+ 
+    ///Returns a reference to the shortest path tree map.
+
+    ///Returns a reference to the NodeMap of the arcs of the
+    ///shortest path tree.
+    ///\pre Either \ref run() or \ref init()
+    ///must be called before using this function.
+    const PredMap &predMap() const { return *_pred;}
+ 
+    ///Checks if a node is reachable from the root.
+
+    ///Returns \c true if \c v is reachable from the root.
+    ///\warning The source nodes are indicated as unreached.
+    ///\pre Either \ref run() or \ref start()
+    ///must be called before using this function.
+    ///
+    bool reached(Node v) { return (*_reached)[v]; }
+    
+    ///@}
+  };
+
+  ///Default traits class of Bfs function.
+
+  ///Default traits class of Bfs function.
+  ///\param GR Digraph type.
+  template<class GR>
+  struct BfsWizardDefaultTraits
+  {
+    ///The digraph type the algorithm runs on. 
+    typedef GR Digraph;
+    ///\brief The type of the map that stores the last
+    ///arcs of the shortest paths.
+    /// 
+    ///The type of the map that stores the last
+    ///arcs of the shortest paths.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap;
+    ///Instantiates a PredMap.
+ 
+    ///This function instantiates a \ref PredMap. 
+    ///\param g is the digraph, to which we would like to define the PredMap.
+    ///\todo The digraph alone may be insufficient to initialize
+#ifdef DOXYGEN
+    static PredMap *createPredMap(const GR &g) 
+#else
+    static PredMap *createPredMap(const GR &) 
+#endif
+    {
+      return new PredMap();
+    }
+
+    ///The type of the map that indicates which nodes are processed.
+ 
+    ///The type of the map that indicates which nodes are processed.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
+    ///Instantiates a ProcessedMap.
+ 
+    ///This function instantiates a \ref ProcessedMap. 
+    ///\param g is the digraph, to which
+    ///we would like to define the \ref ProcessedMap
+#ifdef DOXYGEN
+    static ProcessedMap *createProcessedMap(const GR &g)
+#else
+    static ProcessedMap *createProcessedMap(const GR &)
+#endif
+    {
+      return new ProcessedMap();
+    }
+    ///The type of the map that indicates which nodes are reached.
+ 
+    ///The type of the map that indicates which nodes are reached.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef typename Digraph::template NodeMap<bool> ReachedMap;
+    ///Instantiates a ReachedMap.
+ 
+    ///This function instantiates a \ref ReachedMap. 
+    ///\param G is the digraph, to which
+    ///we would like to define the \ref ReachedMap.
+    static ReachedMap *createReachedMap(const GR &G)
+    {
+      return new ReachedMap(G);
+    }
+    ///The type of the map that stores the dists of the nodes.
+ 
+    ///The type of the map that stores the dists of the nodes.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef NullMap<typename Digraph::Node,int> DistMap;
+    ///Instantiates a DistMap.
+ 
+    ///This function instantiates a \ref DistMap. 
+    ///\param g is the digraph, to which we would like to define the \ref DistMap
+#ifdef DOXYGEN
+    static DistMap *createDistMap(const GR &g)
+#else
+    static DistMap *createDistMap(const GR &)
+#endif
+    {
+      return new DistMap();
+    }
+  };
+  
+  /// Default traits used by \ref BfsWizard
+
+  /// To make it easier to use Bfs algorithm
+  ///we have created a wizard class.
+  /// This \ref BfsWizard class needs default traits,
+  ///as well as the \ref Bfs class.
+  /// The \ref BfsWizardBase is a class to be the default traits of the
+  /// \ref BfsWizard class.
+  template<class GR>
+  class BfsWizardBase : public BfsWizardDefaultTraits<GR>
+  {
+
+    typedef BfsWizardDefaultTraits<GR> Base;
+  protected:
+    /// Type of the nodes in the digraph.
+    typedef typename Base::Digraph::Node Node;
+
+    /// Pointer to the underlying digraph.
+    void *_g;
+    ///Pointer to the map of reached nodes.
+    void *_reached;
+    ///Pointer to the map of processed nodes.
+    void *_processed;
+    ///Pointer to the map of predecessors arcs.
+    void *_pred;
+    ///Pointer to the map of distances.
+    void *_dist;
+    ///Pointer to the source node.
+    Node _source;
+    
+    public:
+    /// Constructor.
+    
+    /// This constructor does not require parameters, therefore it initiates
+    /// all of the attributes to default values (0, INVALID).
+    BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
+			   _dist(0), _source(INVALID) {}
+
+    /// Constructor.
+    
+    /// This constructor requires some parameters,
+    /// listed in the parameters list.
+    /// Others are initiated to 0.
+    /// \param g is the initial value of  \ref _g
+    /// \param s is the initial value of  \ref _source
+    BfsWizardBase(const GR &g, Node s=INVALID) :
+      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
+      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
+
+  };
+  
+  /// A class to make the usage of Bfs algorithm easier
+
+  /// This class is created to make it easier to use Bfs algorithm.
+  /// It uses the functions and features of the plain \ref Bfs,
+  /// but it is much simpler to use it.
+  ///
+  /// Simplicity means that the way to change the types defined
+  /// in the traits class is based on functions that returns the new class
+  /// and not on templatable built-in classes.
+  /// When using the plain \ref Bfs
+  /// the new class with the modified type comes from
+  /// the original class by using the ::
+  /// operator. In the case of \ref BfsWizard only
+  /// a function have to be called and it will
+  /// return the needed class.
+  ///
+  /// It does not have own \ref run method. When its \ref run method is called
+  /// it initiates a plain \ref Bfs class, and calls the \ref Bfs::run
+  /// method of it.
+  template<class TR>
+  class BfsWizard : public TR
+  {
+    typedef TR Base;
+
+    ///The type of the underlying digraph.
+    typedef typename TR::Digraph Digraph;
+    //\e
+    typedef typename Digraph::Node Node;
+    //\e
+    typedef typename Digraph::NodeIt NodeIt;
+    //\e
+    typedef typename Digraph::Arc Arc;
+    //\e
+    typedef typename Digraph::OutArcIt OutArcIt;
+    
+    ///\brief The type of the map that stores
+    ///the reached nodes
+    typedef typename TR::ReachedMap ReachedMap;
+    ///\brief The type of the map that stores
+    ///the processed nodes
+    typedef typename TR::ProcessedMap ProcessedMap;
+    ///\brief The type of the map that stores the last
+    ///arcs of the shortest paths.
+    typedef typename TR::PredMap PredMap;
+    ///The type of the map that stores the dists of the nodes.
+    typedef typename TR::DistMap DistMap;
+
+  public:
+    /// Constructor.
+    BfsWizard() : TR() {}
+
+    /// Constructor that requires parameters.
+
+    /// Constructor that requires parameters.
+    /// These parameters will be the default values for the traits class.
+    BfsWizard(const Digraph &g, Node s=INVALID) :
+      TR(g,s) {}
+
+    ///Copy constructor
+    BfsWizard(const TR &b) : TR(b) {}
+
+    ~BfsWizard() {}
+
+    ///Runs Bfs algorithm from a given node.
+    
+    ///Runs Bfs algorithm from a given node.
+    ///The node can be given by the \ref source function.
+    void run()
+    {
+      if(Base::_source==INVALID) throw UninitializedParameter();
+      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
+      if(Base::_reached)
+	alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
+      if(Base::_processed) 
+        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
+      if(Base::_pred) 
+        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
+      if(Base::_dist) 
+        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
+      alg.run(Base::_source);
+    }
+
+    ///Runs Bfs algorithm from the given node.
+
+    ///Runs Bfs algorithm from the given node.
+    ///\param s is the given source.
+    void run(Node s)
+    {
+      Base::_source=s;
+      run();
+    }
+
+    template<class T>
+    struct DefPredMapBase : public Base {
+      typedef T PredMap;
+      static PredMap *createPredMap(const Digraph &) { return 0; };
+      DefPredMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting PredMap
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting PredMap
+    ///
+    template<class T>
+    BfsWizard<DefPredMapBase<T> > predMap(const T &t) 
+    {
+      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return BfsWizard<DefPredMapBase<T> >(*this);
+    }
+    
+ 
+    template<class T>
+    struct DefReachedMapBase : public Base {
+      typedef T ReachedMap;
+      static ReachedMap *createReachedMap(const Digraph &) { return 0; };
+      DefReachedMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting ReachedMap
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting ReachedMap
+    ///
+    template<class T>
+    BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
+    {
+      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return BfsWizard<DefReachedMapBase<T> >(*this);
+    }
+    
+
+    template<class T>
+    struct DefProcessedMapBase : public Base {
+      typedef T ProcessedMap;
+      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
+      DefProcessedMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting ProcessedMap
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting ProcessedMap
+    ///
+    template<class T>
+    BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
+    {
+      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return BfsWizard<DefProcessedMapBase<T> >(*this);
+    }
+    
+   
+    template<class T>
+    struct DefDistMapBase : public Base {
+      typedef T DistMap;
+      static DistMap *createDistMap(const Digraph &) { return 0; };
+      DefDistMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting DistMap type
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting DistMap type
+    ///
+    template<class T>
+    BfsWizard<DefDistMapBase<T> > distMap(const T &t) 
+    {
+      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return BfsWizard<DefDistMapBase<T> >(*this);
+    }
+    
+    /// Sets the source node, from which the Bfs algorithm runs.
+
+    /// Sets the source node, from which the Bfs algorithm runs.
+    /// \param s is the source node.
+    BfsWizard<TR> &source(Node s) 
+    {
+      Base::_source=s;
+      return *this;
+    }
+    
+  };
+  
+  ///Function type interface for Bfs algorithm.
+
+  /// \ingroup search
+  ///Function type interface for Bfs algorithm.
+  ///
+  ///This function also has several
+  ///\ref named-templ-func-param "named parameters",
+  ///they are declared as the members of class \ref BfsWizard.
+  ///The following
+  ///example shows how to use these parameters.
+  ///\code
+  ///  bfs(g,source).predMap(preds).run();
+  ///\endcode
+  ///\warning Don't forget to put the \ref BfsWizard::run() "run()"
+  ///to the end of the parameter list.
+  ///\sa BfsWizard
+  ///\sa Bfs
+  template<class GR>
+  BfsWizard<BfsWizardBase<GR> >
+  bfs(const GR &g,typename GR::Node s=INVALID)
+  {
+    return BfsWizard<BfsWizardBase<GR> >(g,s);
+  }
+
+#ifdef DOXYGEN
+  /// \brief Visitor class for bfs.
+  ///  
+  /// This class defines the interface of the BfsVisit events, and
+  /// it could be the base of a real Visitor class.
+  template <typename _Digraph>
+  struct BfsVisitor {
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+    typedef typename Digraph::Node Node;
+    /// \brief Called when the arc reach a node.
+    /// 
+    /// It is called when the bfs find an arc which target is not
+    /// reached yet.
+    void discover(const Arc& arc) {}
+    /// \brief Called when the node reached first time.
+    /// 
+    /// It is Called when the node reached first time.
+    void reach(const Node& node) {}
+    /// \brief Called when the arc examined but target of the arc 
+    /// already discovered.
+    /// 
+    /// It called when the arc examined but the target of the arc 
+    /// already discovered.
+    void examine(const Arc& arc) {}
+    /// \brief Called for the source node of the bfs.
+    /// 
+    /// It is called for the source node of the bfs.
+    void start(const Node& node) {}
+    /// \brief Called when the node processed.
+    /// 
+    /// It is Called when the node processed.
+    void process(const Node& node) {}
+  };
+#else
+  template <typename _Digraph>
+  struct BfsVisitor {
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+    typedef typename Digraph::Node Node;
+    void discover(const Arc&) {}
+    void reach(const Node&) {}
+    void examine(const Arc&) {}
+    void start(const Node&) {}
+    void process(const Node&) {}
+
+    template <typename _Visitor>
+    struct Constraints {
+      void constraints() {
+	Arc arc;
+	Node node;
+	visitor.discover(arc);
+	visitor.reach(node);
+	visitor.examine(arc);
+	visitor.start(node);
+        visitor.process(node);
+      }
+      _Visitor& visitor;
+    };
+  };
+#endif
+
+  /// \brief Default traits class of BfsVisit class.
+  ///
+  /// Default traits class of BfsVisit class.
+  /// \param _Digraph Digraph type.
+  template<class _Digraph>
+  struct BfsVisitDefaultTraits {
+
+    /// \brief The digraph type the algorithm runs on. 
+    typedef _Digraph Digraph;
+
+    /// \brief The type of the map that indicates which nodes are reached.
+    /// 
+    /// The type of the map that indicates which nodes are reached.
+    /// It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    /// \todo named parameter to set this type, function to read and write.
+    typedef typename Digraph::template NodeMap<bool> ReachedMap;
+
+    /// \brief Instantiates a ReachedMap.
+    ///
+    /// This function instantiates a \ref ReachedMap. 
+    /// \param digraph is the digraph, to which
+    /// we would like to define the \ref ReachedMap.
+    static ReachedMap *createReachedMap(const Digraph &digraph) {
+      return new ReachedMap(digraph);
+    }
+
+  };
+
+  /// \ingroup search
+  ///  
+  /// \brief %BFS Visit algorithm class.
+  ///  
+  /// This class provides an efficient implementation of the %BFS algorithm
+  /// with visitor interface.
+  ///
+  /// The %BfsVisit class provides an alternative interface to the Bfs
+  /// class. It works with callback mechanism, the BfsVisit object calls
+  /// on every bfs event the \c Visitor class member functions. 
+  ///
+  /// \param _Digraph The digraph type the algorithm runs on. The default value is
+  /// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it
+  /// is only passed to \ref BfsDefaultTraits.
+  /// \param _Visitor The Visitor object for the algorithm. The 
+  /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitor which
+  /// does not observe the Bfs events. If you want to observe the bfs
+  /// events you should implement your own Visitor class.
+  /// \param _Traits Traits class to set various data types used by the 
+  /// algorithm. The default traits class is
+  /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>".
+  /// See \ref BfsVisitDefaultTraits for the documentation of
+  /// a Bfs visit traits class.
+  ///
+  /// \author Jacint Szabo, Alpar Juttner and Balazs Dezso
+#ifdef DOXYGEN
+  template <typename _Digraph, typename _Visitor, typename _Traits>
+#else
+  template <typename _Digraph = ListDigraph,
+	    typename _Visitor = BfsVisitor<_Digraph>,
+	    typename _Traits = BfsDefaultTraits<_Digraph> >
+#endif
+  class BfsVisit {
+  public:
+    
+    /// \brief \ref Exception for uninitialized parameters.
+    ///
+    /// This error represents problems in the initialization
+    /// of the parameters of the algorithms.
+    class UninitializedParameter : public lemon::UninitializedParameter {
+    public:
+      virtual const char* what() const throw() 
+      {
+	return "lemon::BfsVisit::UninitializedParameter";
+      }
+    };
+
+    typedef _Traits Traits;
+
+    typedef typename Traits::Digraph Digraph;
+
+    typedef _Visitor Visitor;
+
+    ///The type of the map indicating which nodes are reached.
+    typedef typename Traits::ReachedMap ReachedMap;
+
+  private:
+
+    typedef typename Digraph::Node Node;
+    typedef typename Digraph::NodeIt NodeIt;
+    typedef typename Digraph::Arc Arc;
+    typedef typename Digraph::OutArcIt OutArcIt;
+
+    /// Pointer to the underlying digraph.
+    const Digraph *_digraph;
+    /// Pointer to the visitor object.
+    Visitor *_visitor;
+    ///Pointer to the map of reached status of the nodes.
+    ReachedMap *_reached;
+    ///Indicates if \ref _reached is locally allocated (\c true) or not.
+    bool local_reached;
+
+    std::vector<typename Digraph::Node> _list;
+    int _list_front, _list_back;
+
+    /// \brief Creates the maps if necessary.
+    ///
+    /// Creates the maps if necessary.
+    void create_maps() {
+      if(!_reached) {
+	local_reached = true;
+	_reached = Traits::createReachedMap(*_digraph);
+      }
+    }
+
+  protected:
+
+    BfsVisit() {}
+    
+  public:
+
+    typedef BfsVisit Create;
+
+    /// \name Named template parameters
+
+    ///@{
+    template <class T>
+    struct DefReachedMapTraits : public Traits {
+      typedef T ReachedMap;
+      static ReachedMap *createReachedMap(const Digraph &digraph) {
+	throw UninitializedParameter();
+      }
+    };
+    /// \brief \ref named-templ-param "Named parameter" for setting 
+    /// ReachedMap type
+    ///
+    /// \ref named-templ-param "Named parameter" for setting ReachedMap type
+    template <class T>
+    struct DefReachedMap : public BfsVisit< Digraph, Visitor,
+					    DefReachedMapTraits<T> > {
+      typedef BfsVisit< Digraph, Visitor, DefReachedMapTraits<T> > Create;
+    };
+    ///@}
+
+  public:      
+    
+    /// \brief Constructor.
+    ///
+    /// Constructor.
+    ///
+    /// \param digraph the digraph the algorithm will run on.
+    /// \param visitor The visitor of the algorithm.
+    ///
+    BfsVisit(const Digraph& digraph, Visitor& visitor) 
+      : _digraph(&digraph), _visitor(&visitor),
+	_reached(0), local_reached(false) {}
+    
+    /// \brief Destructor.
+    ///
+    /// Destructor.
+    ~BfsVisit() {
+      if(local_reached) delete _reached;
+    }
+
+    /// \brief Sets the map indicating if a node is reached.
+    ///
+    /// Sets the map indicating if a node is reached.
+    /// If you don't use this function before calling \ref run(),
+    /// it will allocate one. The destuctor deallocates this
+    /// automatically allocated map, of course.
+    /// \return <tt> (*this) </tt>
+    BfsVisit &reachedMap(ReachedMap &m) {
+      if(local_reached) {
+	delete _reached;
+	local_reached = false;
+      }
+      _reached = &m;
+      return *this;
+    }
+
+  public:
+    /// \name Execution control
+    /// The simplest way to execute the algorithm is to use
+    /// one of the member functions called \c run(...).
+    /// \n
+    /// If you need more control on the execution,
+    /// first you must call \ref init(), then you can adda source node
+    /// with \ref addSource().
+    /// Finally \ref start() will perform the actual path
+    /// computation.
+
+    /// @{
+    /// \brief Initializes the internal data structures.
+    ///
+    /// Initializes the internal data structures.
+    ///
+    void init() {
+      create_maps();
+      _list.resize(countNodes(*_digraph));
+      _list_front = _list_back = -1;
+      for (NodeIt u(*_digraph) ; u != INVALID ; ++u) {
+	_reached->set(u, false);
+      }
+    }
+    
+    /// \brief Adds a new source node.
+    ///
+    /// Adds a new source node to the set of nodes to be processed.
+    void addSource(Node s) {
+      if(!(*_reached)[s]) {
+	  _reached->set(s,true);
+	  _visitor->start(s);
+	  _visitor->reach(s);
+          _list[++_list_back] = s;
+	}
+    }
+    
+    /// \brief Processes the next node.
+    ///
+    /// Processes the next node.
+    ///
+    /// \return The processed node.
+    ///
+    /// \pre The queue must not be empty!
+    Node processNextNode() { 
+      Node n = _list[++_list_front];
+      _visitor->process(n);
+      Arc e;
+      for (_digraph->firstOut(e, n); e != INVALID; _digraph->nextOut(e)) {
+        Node m = _digraph->target(e);
+        if (!(*_reached)[m]) {
+          _visitor->discover(e);
+          _visitor->reach(m);
+          _reached->set(m, true);
+          _list[++_list_back] = m;
+        } else {
+          _visitor->examine(e);
+        }
+      }
+      return n;
+    }
+
+    /// \brief Processes the next node.
+    ///
+    /// Processes the next node. And checks that the given target node
+    /// is reached. If the target node is reachable from the processed
+    /// node then the reached parameter will be set true. The reached
+    /// parameter should be initially false.
+    ///
+    /// \param target The target node.
+    /// \retval reach Indicates that the target node is reached.
+    /// \return The processed node.
+    ///
+    /// \warning The queue must not be empty!
+    Node processNextNode(Node target, bool& reach) {
+      Node n = _list[++_list_front];
+      _visitor->process(n);
+      Arc e;
+      for (_digraph->firstOut(e, n); e != INVALID; _digraph->nextOut(e)) {
+        Node m = _digraph->target(e);
+        if (!(*_reached)[m]) {
+          _visitor->discover(e);
+          _visitor->reach(m);
+          _reached->set(m, true);
+          _list[++_list_back] = m;
+          reach = reach || (target == m);
+        } else {
+          _visitor->examine(e);
+        }
+      }
+      return n;
+    }
+
+    /// \brief Processes the next node.
+    ///
+    /// Processes the next node. And checks that at least one of
+    /// reached node has true value in the \c nm node map. If one node
+    /// with true value is reachable from the processed node then the
+    /// rnode parameter will be set to the first of such nodes.
+    ///
+    /// \param nm The node map of possible targets.
+    /// \retval rnode The reached target node.
+    /// \return The processed node.
+    ///
+    /// \warning The queue must not be empty!
+    template <typename NM>
+    Node processNextNode(const NM& nm, Node& rnode) {
+      Node n = _list[++_list_front];
+      _visitor->process(n);
+      Arc e;
+      for (_digraph->firstOut(e, n); e != INVALID; _digraph->nextOut(e)) {
+        Node m = _digraph->target(e);
+        if (!(*_reached)[m]) {
+          _visitor->discover(e);
+          _visitor->reach(m);
+          _reached->set(m, true);
+          _list[++_list_back] = m;
+          if (nm[m] && rnode == INVALID) rnode = m;
+        } else {
+          _visitor->examine(e);
+        }
+      }
+      return n;
+    }
+
+    /// \brief Next node to be processed.
+    ///
+    /// Next node to be processed.
+    ///
+    /// \return The next node to be processed or INVALID if the stack is
+    /// empty.
+    Node nextNode() { 
+      return _list_front != _list_back ? _list[_list_front + 1] : INVALID;
+    }
+
+    /// \brief Returns \c false if there are nodes
+    /// to be processed in the queue
+    ///
+    /// Returns \c false if there are nodes
+    /// to be processed in the queue
+    bool emptyQueue() { return _list_front == _list_back; }
+
+    /// \brief Returns the number of the nodes to be processed.
+    ///
+    /// Returns the number of the nodes to be processed in the queue.
+    int queueSize() { return _list_back - _list_front; }
+    
+    /// \brief Executes the algorithm.
+    ///
+    /// Executes the algorithm.
+    ///
+    /// \pre init() must be called and at least one node should be added
+    /// with addSource() before using this function.
+    void start() {
+      while ( !emptyQueue() ) processNextNode();
+    }
+    
+    /// \brief Executes the algorithm until \c dest is reached.
+    ///
+    /// Executes the algorithm until \c dest is reached.
+    ///
+    /// \pre init() must be called and at least one node should be added
+    /// with addSource() before using this function.
+    void start(Node dest) {
+      bool reach = false;
+      while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
+    }
+    
+    /// \brief Executes the algorithm until a condition is met.
+    ///
+    /// Executes the algorithm until a condition is met.
+    ///
+    /// \pre init() must be called and at least one node should be added
+    /// with addSource() before using this function.
+    ///
+    ///\param nm must be a bool (or convertible) node map. The
+    ///algorithm will stop when it reaches a node \c v with
+    /// <tt>nm[v]</tt> true.
+    ///
+    ///\return The reached node \c v with <tt>nm[v]</tt> true or
+    ///\c INVALID if no such node was found.
+    template <typename NM>
+    Node start(const NM &nm) {
+      Node rnode = INVALID;
+      while ( !emptyQueue() && rnode == INVALID ) {
+	processNextNode(nm, rnode);
+      }
+      return rnode;
+    }
+
+    /// \brief Runs %BFSVisit algorithm from node \c s.
+    ///
+    /// This method runs the %BFS algorithm from a root node \c s.
+    /// \note b.run(s) is just a shortcut of the following code.
+    ///\code
+    ///   b.init();
+    ///   b.addSource(s);
+    ///   b.start();
+    ///\endcode
+    void run(Node s) {
+      init();
+      addSource(s);
+      start();
+    }
+
+    /// \brief Runs %BFSVisit algorithm to visit all nodes in the digraph.
+    ///    
+    /// This method runs the %BFS algorithm in order to
+    /// compute the %BFS path to each node. The algorithm computes
+    /// - The %BFS tree.
+    /// - The distance of each node from the root in the %BFS tree.
+    ///
+    ///\note b.run() is just a shortcut of the following code.
+    ///\code
+    ///  b.init();
+    ///  for (NodeIt it(digraph); it != INVALID; ++it) {
+    ///    if (!b.reached(it)) {
+    ///      b.addSource(it);
+    ///      b.start();
+    ///    }
+    ///  }
+    ///\endcode
+    void run() {
+      init();
+      for (NodeIt it(*_digraph); it != INVALID; ++it) {
+        if (!reached(it)) {
+          addSource(it);
+          start();
+        }
+      }
+    }
+    ///@}
+
+    /// \name Query Functions
+    /// The result of the %BFS algorithm can be obtained using these
+    /// functions.\n
+    /// Before the use of these functions,
+    /// either run() or start() must be called.
+    ///@{
+
+    /// \brief Checks if a node is reachable from the root.
+    ///
+    /// Returns \c true if \c v is reachable from the root(s).
+    /// \warning The source nodes are inditated as unreachable.
+    /// \pre Either \ref run() or \ref start()
+    /// must be called before using this function.
+    ///
+    bool reached(Node v) { return (*_reached)[v]; }
+    ///@}
+  };
+
+} //END OF NAMESPACE LEMON
+
+#endif
+
Index: lemon/bin_heap.h
===================================================================
--- lemon/bin_heap.h	(revision 100)
+++ lemon/bin_heap.h	(revision 100)
@@ -0,0 +1,346 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_BIN_HEAP_H
+#define LEMON_BIN_HEAP_H
+
+///\ingroup auxdat
+///\file
+///\brief Binary Heap implementation.
+
+#include <vector>
+#include <utility>
+#include <functional>
+
+namespace lemon {
+
+  ///\ingroup auxdat
+  ///
+  ///\brief A Binary Heap implementation.
+  ///
+  ///This class implements the \e binary \e heap data structure. A \e heap
+  ///is a data structure for storing items with specified values called \e
+  ///priorities in such a way that finding the item with minimum priority is
+  ///efficient. \c Compare specifies the ordering of the priorities. In a heap
+  ///one can change the priority of an item, add or erase an item, etc.
+  ///
+  ///\param _Prio Type of the priority of the items.
+  ///\param _ItemIntMap A read and writable Item int map, used internally
+  ///to handle the cross references.
+  ///\param _Compare A class for the ordering of the priorities. The
+  ///default is \c std::less<_Prio>.
+  ///
+  ///\sa FibHeap
+  ///\sa Dijkstra
+  template <typename _Prio, typename _ItemIntMap,
+	    typename _Compare = std::less<_Prio> >
+  class BinHeap {
+
+  public:
+    ///\e
+    typedef _ItemIntMap ItemIntMap;
+    ///\e
+    typedef _Prio Prio;
+    ///\e
+    typedef typename ItemIntMap::Key Item;
+    ///\e
+    typedef std::pair<Item,Prio> Pair;
+    ///\e
+    typedef _Compare Compare;
+
+    /// \brief Type to represent the items states.
+    ///
+    /// Each Item element have a state associated to it. It may be "in heap",
+    /// "pre heap" or "post heap". The latter two are indifferent from the
+    /// heap's point of view, but may be useful to the user.
+    ///
+    /// The ItemIntMap \e should be initialized in such way that it maps
+    /// PRE_HEAP (-1) to any element to be put in the heap...
+    enum State {
+      IN_HEAP = 0,
+      PRE_HEAP = -1,
+      POST_HEAP = -2
+    };
+
+  private:
+    std::vector<Pair> data;
+    Compare comp;
+    ItemIntMap &iim;
+
+  public:
+    /// \brief The constructor.
+    ///
+    /// The constructor.
+    /// \param _iim should be given to the constructor, since it is used
+    /// internally to handle the cross references. The value of the map
+    /// should be PRE_HEAP (-1) for each element.
+    explicit BinHeap(ItemIntMap &_iim) : iim(_iim) {}
+    
+    /// \brief The constructor.
+    ///
+    /// The constructor.
+    /// \param _iim should be given to the constructor, since it is used
+    /// internally to handle the cross references. The value of the map
+    /// should be PRE_HEAP (-1) for each element.
+    ///
+    /// \param _comp The comparator function object.
+    BinHeap(ItemIntMap &_iim, const Compare &_comp) 
+      : iim(_iim), comp(_comp) {}
+
+
+    /// The number of items stored in the heap.
+    ///
+    /// \brief Returns the number of items stored in the heap.
+    int size() const { return data.size(); }
+    
+    /// \brief Checks if the heap stores no items.
+    ///
+    /// Returns \c true if and only if the heap stores no items.
+    bool empty() const { return data.empty(); }
+
+    /// \brief Make empty this heap.
+    /// 
+    /// Make empty this heap. It does not change the cross reference map.
+    /// If you want to reuse what is not surely empty you should first clear
+    /// the heap and after that you should set the cross reference map for
+    /// each item to \c PRE_HEAP.
+    void clear() { 
+      data.clear(); 
+    }
+
+  private:
+    static int parent(int i) { return (i-1)/2; }
+
+    static int second_child(int i) { return 2*i+2; }
+    bool less(const Pair &p1, const Pair &p2) const {
+      return comp(p1.second, p2.second);
+    }
+
+    int bubble_up(int hole, Pair p) {
+      int par = parent(hole);
+      while( hole>0 && less(p,data[par]) ) {
+	move(data[par],hole);
+	hole = par;
+	par = parent(hole);
+      }
+      move(p, hole);
+      return hole;
+    }
+
+    int bubble_down(int hole, Pair p, int length) {
+      int child = second_child(hole);
+      while(child < length) {
+	if( less(data[child-1], data[child]) ) {
+	  --child;
+	}
+	if( !less(data[child], p) )
+	  goto ok;
+	move(data[child], hole);
+	hole = child;
+	child = second_child(hole);
+      }
+      child--;
+      if( child<length && less(data[child], p) ) {
+	move(data[child], hole);
+	hole=child;
+      }
+    ok:
+      move(p, hole);
+      return hole;
+    }
+
+    void move(const Pair &p, int i) {
+      data[i] = p;
+      iim.set(p.first, i);
+    }
+
+  public:
+    /// \brief Insert a pair of item and priority into the heap.
+    ///
+    /// Adds \c p.first to the heap with priority \c p.second.
+    /// \param p The pair to insert.
+    void push(const Pair &p) {
+      int n = data.size();
+      data.resize(n+1);
+      bubble_up(n, p);
+    }
+
+    /// \brief Insert an item into the heap with the given heap.
+    ///    
+    /// Adds \c i to the heap with priority \c p. 
+    /// \param i The item to insert.
+    /// \param p The priority of the item.
+    void push(const Item &i, const Prio &p) { push(Pair(i,p)); }
+
+    /// \brief Returns the item with minimum priority relative to \c Compare.
+    ///
+    /// This method returns the item with minimum priority relative to \c
+    /// Compare.  
+    /// \pre The heap must be nonempty.  
+    Item top() const {
+      return data[0].first;
+    }
+
+    /// \brief Returns the minimum priority relative to \c Compare.
+    ///
+    /// It returns the minimum priority relative to \c Compare.
+    /// \pre The heap must be nonempty.
+    Prio prio() const {
+      return data[0].second;
+    }
+
+    /// \brief Deletes the item with minimum priority relative to \c Compare.
+    ///
+    /// This method deletes the item with minimum priority relative to \c
+    /// Compare from the heap.  
+    /// \pre The heap must be non-empty.  
+    void pop() {
+      int n = data.size()-1;
+      iim.set(data[0].first, POST_HEAP);
+      if (n > 0) {
+	bubble_down(0, data[n], n);
+      }
+      data.pop_back();
+    }
+
+    /// \brief Deletes \c i from the heap.
+    ///
+    /// This method deletes item \c i from the heap.
+    /// \param i The item to erase.
+    /// \pre The item should be in the heap.
+    void erase(const Item &i) {
+      int h = iim[i];
+      int n = data.size()-1;
+      iim.set(data[h].first, POST_HEAP);
+      if( h < n ) {
+	if ( bubble_up(h, data[n]) == h) {
+	  bubble_down(h, data[n], n);
+	}
+      }
+      data.pop_back();
+    }
+
+    
+    /// \brief Returns the priority of \c i.
+    ///
+    /// This function returns the priority of item \c i.  
+    /// \pre \c i must be in the heap.
+    /// \param i The item.
+    Prio operator[](const Item &i) const {
+      int idx = iim[i];
+      return data[idx].second;
+    }
+
+    /// \brief \c i gets to the heap with priority \c p independently 
+    /// if \c i was already there.
+    ///
+    /// This method calls \ref push(\c i, \c p) if \c i is not stored
+    /// in the heap and sets the priority of \c i to \c p otherwise.
+    /// \param i The item.
+    /// \param p The priority.
+    void set(const Item &i, const Prio &p) {
+      int idx = iim[i];
+      if( idx < 0 ) {
+	push(i,p);
+      }
+      else if( comp(p, data[idx].second) ) {
+	bubble_up(idx, Pair(i,p));
+      }
+      else {
+	bubble_down(idx, Pair(i,p), data.size());
+      }
+    }
+
+    /// \brief Decreases the priority of \c i to \c p.
+    ///
+    /// This method decreases the priority of item \c i to \c p.
+    /// \pre \c i must be stored in the heap with priority at least \c
+    /// p relative to \c Compare.
+    /// \param i The item.
+    /// \param p The priority.
+    void decrease(const Item &i, const Prio &p) {
+      int idx = iim[i];
+      bubble_up(idx, Pair(i,p));
+    }
+    
+    /// \brief Increases the priority of \c i to \c p.
+    ///
+    /// This method sets the priority of item \c i to \c p. 
+    /// \pre \c i must be stored in the heap with priority at most \c
+    /// p relative to \c Compare.
+    /// \param i The item.
+    /// \param p The priority.
+    void increase(const Item &i, const Prio &p) {
+      int idx = iim[i];
+      bubble_down(idx, Pair(i,p), data.size());
+    }
+
+    /// \brief Returns if \c item is in, has already been in, or has 
+    /// never been in the heap.
+    ///
+    /// This method returns PRE_HEAP if \c item has never been in the
+    /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
+    /// otherwise. In the latter case it is possible that \c item will
+    /// get back to the heap again.
+    /// \param i The item.
+    State state(const Item &i) const {
+      int s = iim[i];
+      if( s>=0 )
+	s=0;
+      return State(s);
+    }
+
+    /// \brief Sets the state of the \c item in the heap.
+    ///
+    /// Sets the state of the \c item in the heap. It can be used to
+    /// manually clear the heap when it is important to achive the
+    /// better time complexity.
+    /// \param i The item.
+    /// \param st The state. It should not be \c IN_HEAP. 
+    void state(const Item& i, State st) {
+      switch (st) {
+      case POST_HEAP:
+      case PRE_HEAP:
+        if (state(i) == IN_HEAP) {
+          erase(i);
+        }
+        iim[i] = st;
+        break;
+      case IN_HEAP:
+        break;
+      }
+    }
+
+    /// \brief Replaces an item in the heap.
+    ///
+    /// The \c i item is replaced with \c j item. The \c i item should
+    /// be in the heap, while the \c j should be out of the heap. The
+    /// \c i item will out of the heap and \c j will be in the heap
+    /// with the same prioriority as prevoiusly the \c i item.
+    void replace(const Item& i, const Item& j) {
+      int idx = iim[i];
+      iim.set(i, iim[j]);
+      iim.set(j, idx);
+      data[idx].first = j;
+    }
+
+  }; // class BinHeap
+  
+} // namespace lemon
+
+#endif // LEMON_BIN_HEAP_H
Index: lemon/bits/graph_extender.h
===================================================================
--- lemon/bits/graph_extender.h	(revision 77)
+++ lemon/bits/graph_extender.h	(revision 78)
@@ -65,9 +65,9 @@
     }
 
-    Node oppositeNode(const Node &n, const Arc &e) const {
-      if (n == Parent::source(e))
-	return Parent::target(e);
-      else if(n==Parent::target(e))
-	return Parent::source(e);
+    Node oppositeNode(const Node &node, const Arc &arc) const {
+      if (node == Parent::source(arc))
+	return Parent::target(arc);
+      else if(node == Parent::target(arc))
+	return Parent::source(arc);
       else
 	return INVALID;
@@ -96,5 +96,5 @@
 
     class NodeIt : public Node { 
-      const Digraph* digraph;
+      const Digraph* _digraph;
     public:
 
@@ -103,13 +103,13 @@
       NodeIt(Invalid i) : Node(i) { }
 
-      explicit NodeIt(const Digraph& _digraph) : digraph(&_digraph) {
-	_digraph.first(static_cast<Node&>(*this));
-      }
-
-      NodeIt(const Digraph& _digraph, const Node& node) 
-	: Node(node), digraph(&_digraph) {}
+      explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) {
+	_digraph->first(static_cast<Node&>(*this));
+      }
+
+      NodeIt(const Digraph& digraph, const Node& node) 
+	: Node(node), _digraph(&digraph) {}
 
       NodeIt& operator++() { 
-	digraph->next(*this);
+	_digraph->next(*this);
 	return *this; 
       }
@@ -119,5 +119,5 @@
 
     class ArcIt : public Arc { 
-      const Digraph* digraph;
+      const Digraph* _digraph;
     public:
 
@@ -126,13 +126,13 @@
       ArcIt(Invalid i) : Arc(i) { }
 
-      explicit ArcIt(const Digraph& _digraph) : digraph(&_digraph) {
-	_digraph.first(static_cast<Arc&>(*this));
-      }
-
-      ArcIt(const Digraph& _digraph, const Arc& e) : 
-	Arc(e), digraph(&_digraph) { }
+      explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) {
+	_digraph->first(static_cast<Arc&>(*this));
+      }
+
+      ArcIt(const Digraph& digraph, const Arc& arc) : 
+	Arc(arc), _digraph(&digraph) { }
 
       ArcIt& operator++() { 
-	digraph->next(*this);
+	_digraph->next(*this);
 	return *this; 
       }
@@ -142,5 +142,5 @@
 
     class OutArcIt : public Arc { 
-      const Digraph* digraph;
+      const Digraph* _digraph;
     public:
 
@@ -149,14 +149,14 @@
       OutArcIt(Invalid i) : Arc(i) { }
 
-      OutArcIt(const Digraph& _digraph, const Node& node) 
-	: digraph(&_digraph) {
-	_digraph.firstOut(*this, node);
-      }
-
-      OutArcIt(const Digraph& _digraph, const Arc& arc) 
-	: Arc(arc), digraph(&_digraph) {}
+      OutArcIt(const Digraph& digraph, const Node& node) 
+	: _digraph(&digraph) {
+	_digraph->firstOut(*this, node);
+      }
+
+      OutArcIt(const Digraph& digraph, const Arc& arc) 
+	: Arc(arc), _digraph(&digraph) {}
 
       OutArcIt& operator++() { 
-	digraph->nextOut(*this);
+	_digraph->nextOut(*this);
 	return *this; 
       }
@@ -166,5 +166,5 @@
 
     class InArcIt : public Arc { 
-      const Digraph* digraph;
+      const Digraph* _digraph;
     public:
 
@@ -173,14 +173,14 @@
       InArcIt(Invalid i) : Arc(i) { }
 
-      InArcIt(const Digraph& _digraph, const Node& node) 
-	: digraph(&_digraph) {
-	_digraph.firstIn(*this, node);
-      }
-
-      InArcIt(const Digraph& _digraph, const Arc& arc) : 
-	Arc(arc), digraph(&_digraph) {}
+      InArcIt(const Digraph& digraph, const Node& node) 
+	: _digraph(&digraph) {
+	_digraph->firstIn(*this, node);
+      }
+
+      InArcIt(const Digraph& digraph, const Arc& arc) : 
+	Arc(arc), _digraph(&digraph) {}
 
       InArcIt& operator++() { 
-	digraph->nextIn(*this);
+	_digraph->nextIn(*this);
 	return *this; 
       }
@@ -191,6 +191,6 @@
     ///
     /// Returns the base node (i.e. the source in this case) of the iterator
-    Node baseNode(const OutArcIt &e) const {
-      return Parent::source(e);
+    Node baseNode(const OutArcIt &arc) const {
+      return Parent::source(arc);
     }
     /// \brief Running node of the iterator
@@ -198,6 +198,6 @@
     /// Returns the running node (i.e. the target in this case) of the
     /// iterator
-    Node runningNode(const OutArcIt &e) const {
-      return Parent::target(e);
+    Node runningNode(const OutArcIt &arc) const {
+      return Parent::target(arc);
     }
 
@@ -205,6 +205,6 @@
     ///
     /// Returns the base node (i.e. the target in this case) of the iterator
-    Node baseNode(const InArcIt &e) const {
-      return Parent::target(e);
+    Node baseNode(const InArcIt &arc) const {
+      return Parent::target(arc);
     }
     /// \brief Running node of the iterator
@@ -212,6 +212,6 @@
     /// Returns the running node (i.e. the source in this case) of the
     /// iterator
-    Node runningNode(const InArcIt &e) const {
-      return Parent::source(e);
+    Node runningNode(const InArcIt &arc) const {
+      return Parent::source(arc);
     }
 
@@ -325,5 +325,5 @@
   };
 
-  /// \ingroup graphbits
+  /// \ingroup _graphbits
   ///
   /// \brief Extender for the Graphs
@@ -333,5 +333,5 @@
     
     typedef Base Parent;
-    typedef GraphExtender Digraph;
+    typedef GraphExtender Graph;
 
     typedef True UndirectedTag;
@@ -376,11 +376,11 @@
     }
 
-    Arc oppositeArc(const Arc &e) const {
-      return Parent::direct(e, !Parent::direction(e));
+    Arc oppositeArc(const Arc &arc) const {
+      return Parent::direct(arc, !Parent::direction(arc));
     }
 
     using Parent::direct;
-    Arc direct(const Edge &ue, const Node &s) const {
-      return Parent::direct(ue, Parent::source(ue) == s);
+    Arc direct(const Edge &edge, const Node &node) const {
+      return Parent::direct(edge, Parent::source(edge) == node);
     }
 
@@ -415,5 +415,5 @@
 
     class NodeIt : public Node { 
-      const Digraph* digraph;
+      const Graph* _graph;
     public:
 
@@ -422,13 +422,13 @@
       NodeIt(Invalid i) : Node(i) { }
 
-      explicit NodeIt(const Digraph& _digraph) : digraph(&_digraph) {
-	_digraph.first(static_cast<Node&>(*this));
-      }
-
-      NodeIt(const Digraph& _digraph, const Node& node) 
-	: Node(node), digraph(&_digraph) {}
+      explicit NodeIt(const Graph& graph) : _graph(&graph) {
+	_graph->first(static_cast<Node&>(*this));
+      }
+
+      NodeIt(const Graph& graph, const Node& node) 
+	: Node(node), _graph(&graph) {}
 
       NodeIt& operator++() { 
-	digraph->next(*this);
+	_graph->next(*this);
 	return *this; 
       }
@@ -438,5 +438,5 @@
 
     class ArcIt : public Arc { 
-      const Digraph* digraph;
+      const Graph* _graph;
     public:
 
@@ -445,13 +445,13 @@
       ArcIt(Invalid i) : Arc(i) { }
 
-      explicit ArcIt(const Digraph& _digraph) : digraph(&_digraph) {
-	_digraph.first(static_cast<Arc&>(*this));
-      }
-
-      ArcIt(const Digraph& _digraph, const Arc& e) : 
-	Arc(e), digraph(&_digraph) { }
+      explicit ArcIt(const Graph& graph) : _graph(&graph) {
+	_graph->first(static_cast<Arc&>(*this));
+      }
+
+      ArcIt(const Graph& graph, const Arc& arc) : 
+	Arc(arc), _graph(&graph) { }
 
       ArcIt& operator++() { 
-	digraph->next(*this);
+	_graph->next(*this);
 	return *this; 
       }
@@ -461,5 +461,5 @@
 
     class OutArcIt : public Arc { 
-      const Digraph* digraph;
+      const Graph* _graph;
     public:
 
@@ -468,14 +468,14 @@
       OutArcIt(Invalid i) : Arc(i) { }
 
-      OutArcIt(const Digraph& _digraph, const Node& node) 
-	: digraph(&_digraph) {
-	_digraph.firstOut(*this, node);
-      }
-
-      OutArcIt(const Digraph& _digraph, const Arc& arc) 
-	: Arc(arc), digraph(&_digraph) {}
+      OutArcIt(const Graph& graph, const Node& node) 
+	: _graph(&graph) {
+	_graph->firstOut(*this, node);
+      }
+
+      OutArcIt(const Graph& graph, const Arc& arc) 
+	: Arc(arc), _graph(&graph) {}
 
       OutArcIt& operator++() { 
-	digraph->nextOut(*this);
+	_graph->nextOut(*this);
 	return *this; 
       }
@@ -485,5 +485,5 @@
 
     class InArcIt : public Arc { 
-      const Digraph* digraph;
+      const Graph* _graph;
     public:
 
@@ -492,14 +492,14 @@
       InArcIt(Invalid i) : Arc(i) { }
 
-      InArcIt(const Digraph& _digraph, const Node& node) 
-	: digraph(&_digraph) {
-	_digraph.firstIn(*this, node);
-      }
-
-      InArcIt(const Digraph& _digraph, const Arc& arc) : 
-	Arc(arc), digraph(&_digraph) {}
+      InArcIt(const Graph& graph, const Node& node) 
+	: _graph(&graph) {
+	_graph->firstIn(*this, node);
+      }
+
+      InArcIt(const Graph& graph, const Arc& arc) : 
+	Arc(arc), _graph(&graph) {}
 
       InArcIt& operator++() { 
-	digraph->nextIn(*this);
+	_graph->nextIn(*this);
 	return *this; 
       }
@@ -509,5 +509,5 @@
 
     class EdgeIt : public Parent::Edge { 
-      const Digraph* digraph;
+      const Graph* _graph;
     public:
 
@@ -516,39 +516,39 @@
       EdgeIt(Invalid i) : Edge(i) { }
 
-      explicit EdgeIt(const Digraph& _digraph) : digraph(&_digraph) {
-	_digraph.first(static_cast<Edge&>(*this));
-      }
-
-      EdgeIt(const Digraph& _digraph, const Edge& e) : 
-	Edge(e), digraph(&_digraph) { }
+      explicit EdgeIt(const Graph& graph) : _graph(&graph) {
+	_graph->first(static_cast<Edge&>(*this));
+      }
+
+      EdgeIt(const Graph& graph, const Edge& edge) : 
+	Edge(edge), _graph(&graph) { }
 
       EdgeIt& operator++() { 
-	digraph->next(*this);
-	return *this; 
-      }
-
-    };
-
-    class IncArcIt : public Parent::Edge {
+	_graph->next(*this);
+	return *this; 
+      }
+
+    };
+
+    class IncEdgeIt : public Parent::Edge {
       friend class GraphExtender;
-      const Digraph* digraph;
-      bool direction;
-    public:
-
-      IncArcIt() { }
-
-      IncArcIt(Invalid i) : Edge(i), direction(false) { }
-
-      IncArcIt(const Digraph& _digraph, const Node &n) : digraph(&_digraph) {
-	_digraph.firstInc(*this, direction, n);
-      }
-
-      IncArcIt(const Digraph& _digraph, const Edge &ue, const Node &n)
-	: digraph(&_digraph), Edge(ue) {
-	direction = (_digraph.source(ue) == n);
-      }
-
-      IncArcIt& operator++() {
-	digraph->nextInc(*this, direction);
+      const Graph* _graph;
+      bool _direction;
+    public:
+
+      IncEdgeIt() { }
+
+      IncEdgeIt(Invalid i) : Edge(i), _direction(false) { }
+
+      IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) {
+	_graph->firstInc(*this, _direction, node);
+      }
+
+      IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node)
+	: _graph(&graph), Edge(edge) {
+	_direction = (_graph->source(edge) == node);
+      }
+
+      IncEdgeIt& operator++() {
+	_graph->nextInc(*this, _direction);
 	return *this; 
       }
@@ -558,6 +558,6 @@
     ///
     /// Returns the base node (ie. the source in this case) of the iterator
-    Node baseNode(const OutArcIt &e) const {
-      return Parent::source(static_cast<const Arc&>(e));
+    Node baseNode(const OutArcIt &arc) const {
+      return Parent::source(static_cast<const Arc&>(arc));
     }
     /// \brief Running node of the iterator
@@ -565,6 +565,6 @@
     /// Returns the running node (ie. the target in this case) of the
     /// iterator
-    Node runningNode(const OutArcIt &e) const {
-      return Parent::target(static_cast<const Arc&>(e));
+    Node runningNode(const OutArcIt &arc) const {
+      return Parent::target(static_cast<const Arc&>(arc));
     }
 
@@ -572,6 +572,6 @@
     ///
     /// Returns the base node (ie. the target in this case) of the iterator
-    Node baseNode(const InArcIt &e) const {
-      return Parent::target(static_cast<const Arc&>(e));
+    Node baseNode(const InArcIt &arc) const {
+      return Parent::target(static_cast<const Arc&>(arc));
     }
     /// \brief Running node of the iterator
@@ -579,6 +579,6 @@
     /// Returns the running node (ie. the source in this case) of the
     /// iterator
-    Node runningNode(const InArcIt &e) const {
-      return Parent::source(static_cast<const Arc&>(e));
+    Node runningNode(const InArcIt &arc) const {
+      return Parent::source(static_cast<const Arc&>(arc));
     }
 
@@ -586,12 +586,12 @@
     ///
     /// Returns the base node of the iterator
-    Node baseNode(const IncArcIt &e) const {
-      return e.direction ? source(e) : target(e);
+    Node baseNode(const IncEdgeIt &edge) const {
+      return edge._direction ? source(edge) : target(edge);
     }
     /// Running node of the iterator
     ///
     /// Returns the running node of the iterator
-    Node runningNode(const IncArcIt &e) const {
-      return e.direction ? target(e) : source(e);
+    Node runningNode(const IncEdgeIt &edge) const {
+      return edge._direction ? target(edge) : source(edge);
     }
 
@@ -600,13 +600,13 @@
     template <typename _Value>
     class NodeMap 
-      : public MapExtender<DefaultMap<Digraph, Node, _Value> > {
-    public:
-      typedef GraphExtender Digraph;
-      typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent;
-
-      NodeMap(const Digraph& digraph) 
-	: Parent(digraph) {}
-      NodeMap(const Digraph& digraph, const _Value& value) 
-	: Parent(digraph, value) {}
+      : public MapExtender<DefaultMap<Graph, Node, _Value> > {
+    public:
+      typedef GraphExtender Graph;
+      typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
+
+      NodeMap(const Graph& graph) 
+	: Parent(graph) {}
+      NodeMap(const Graph& graph, const _Value& value) 
+	: Parent(graph, value) {}
 
       NodeMap& operator=(const NodeMap& cmap) {
@@ -624,13 +624,13 @@
     template <typename _Value>
     class ArcMap 
-      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
-    public:
-      typedef GraphExtender Digraph;
-      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
-
-      ArcMap(const Digraph& digraph) 
-	: Parent(digraph) {}
-      ArcMap(const Digraph& digraph, const _Value& value) 
-	: Parent(digraph, value) {}
+      : public MapExtender<DefaultMap<Graph, Arc, _Value> > {
+    public:
+      typedef GraphExtender Graph;
+      typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
+
+      ArcMap(const Graph& graph) 
+	: Parent(graph) {}
+      ArcMap(const Graph& graph, const _Value& value) 
+	: Parent(graph, value) {}
 
       ArcMap& operator=(const ArcMap& cmap) {
@@ -648,14 +648,14 @@
     template <typename _Value>
     class EdgeMap 
-      : public MapExtender<DefaultMap<Digraph, Edge, _Value> > {
-    public:
-      typedef GraphExtender Digraph;
-      typedef MapExtender<DefaultMap<Digraph, Edge, _Value> > Parent;
-
-      EdgeMap(const Digraph& digraph) 
-	: Parent(digraph) {}
-
-      EdgeMap(const Digraph& digraph, const _Value& value) 
-	: Parent(digraph, value) {}
+      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
+    public:
+      typedef GraphExtender Graph;
+      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
+
+      EdgeMap(const Graph& graph) 
+	: Parent(graph) {}
+
+      EdgeMap(const Graph& graph, const _Value& value) 
+	: Parent(graph, value) {}
 
       EdgeMap& operator=(const EdgeMap& cmap) {
@@ -696,8 +696,8 @@
     }
 
-    template <typename Digraph, typename NodeRefMap, typename EdgeRefMap>
-    void build(const Digraph& digraph, NodeRefMap& nodeRef, 
+    template <typename Graph, typename NodeRefMap, typename EdgeRefMap>
+    void build(const Graph& graph, NodeRefMap& nodeRef, 
                EdgeRefMap& edgeRef) {
-      Parent::build(digraph, nodeRef, edgeRef);
+      Parent::build(graph, nodeRef, edgeRef);
       notifier(Node()).build();
       notifier(Edge()).build();
@@ -724,8 +724,8 @@
 
     void erase(const Edge& edge) {
-      std::vector<Arc> ev;
-      ev.push_back(Parent::direct(edge, true));
-      ev.push_back(Parent::direct(edge, false));      
-      notifier(Arc()).erase(ev);
+      std::vector<Arc> av;
+      av.push_back(Parent::direct(edge, true));
+      av.push_back(Parent::direct(edge, false));      
+      notifier(Arc()).erase(av);
       notifier(Edge()).erase(edge);
       Parent::erase(edge);
Index: lemon/bits/path_dump.h
===================================================================
--- lemon/bits/path_dump.h	(revision 100)
+++ lemon/bits/path_dump.h	(revision 100)
@@ -0,0 +1,174 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_BITS_PRED_MAP_PATH_H
+#define LEMON_BITS_PRED_MAP_PATH_H
+
+namespace lemon {
+
+  template <typename _Digraph, typename _PredMap>
+  class PredMapPath {
+  public:
+    typedef True RevPathTag;
+
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+    typedef _PredMap PredMap;
+
+    PredMapPath(const Digraph& _digraph, const PredMap& _predMap,
+                typename Digraph::Node _target)
+      : digraph(_digraph), predMap(_predMap), target(_target) {}
+
+    int length() const {
+      int len = 0;
+      typename Digraph::Node node = target;
+      typename Digraph::Arc arc;
+      while ((arc = predMap[node]) != INVALID) {
+        node = digraph.source(arc);
+        ++len;
+      }
+      return len;
+    }
+
+    bool empty() const {
+      return predMap[target] != INVALID;
+    }
+
+    class RevArcIt {
+    public:
+      RevArcIt() {}
+      RevArcIt(Invalid) : path(0), current(INVALID) {}
+      RevArcIt(const PredMapPath& _path) 
+        : path(&_path), current(_path.target) {
+        if (path->predMap[current] == INVALID) current = INVALID;
+      }
+
+      operator const typename Digraph::Arc() const {
+        return path->predMap[current];
+      }
+
+      RevArcIt& operator++() {
+        current = path->digraph.source(path->predMap[current]);
+        if (path->predMap[current] == INVALID) current = INVALID;
+        return *this;
+      }
+
+      bool operator==(const RevArcIt& e) const { 
+        return current == e.current; 
+      }
+
+      bool operator!=(const RevArcIt& e) const {
+        return current != e.current; 
+      }
+
+      bool operator<(const RevArcIt& e) const { 
+        return current < e.current; 
+      }
+      
+    private:
+      const PredMapPath* path;
+      typename Digraph::Node current;
+    };
+
+  private:
+    const Digraph& digraph;
+    const PredMap& predMap;
+    typename Digraph::Node target;
+  };
+
+
+  template <typename _Digraph, typename _PredMatrixMap>
+  class PredMatrixMapPath {
+  public:
+    typedef True RevPathTag;
+
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+    typedef _PredMatrixMap PredMatrixMap;
+
+    PredMatrixMapPath(const Digraph& _digraph, 
+                      const PredMatrixMap& _predMatrixMap,
+                      typename Digraph::Node _source, 
+                      typename Digraph::Node _target)
+      : digraph(_digraph), predMatrixMap(_predMatrixMap), 
+        source(_source), target(_target) {}
+
+    int length() const {
+      int len = 0;
+      typename Digraph::Node node = target;
+      typename Digraph::Arc arc;
+      while ((arc = predMatrixMap(source, node)) != INVALID) {
+        node = digraph.source(arc);
+        ++len;
+      }
+      return len;
+    }
+
+    bool empty() const {
+      return source != target;
+    }
+
+    class RevArcIt {
+    public:
+      RevArcIt() {}
+      RevArcIt(Invalid) : path(0), current(INVALID) {}
+      RevArcIt(const PredMatrixMapPath& _path) 
+        : path(&_path), current(_path.target) {
+        if (path->predMatrixMap(path->source, current) == INVALID) 
+          current = INVALID;
+      }
+
+      operator const typename Digraph::Arc() const {
+        return path->predMatrixMap(path->source, current);
+      }
+
+      RevArcIt& operator++() {
+        current = 
+          path->digraph.source(path->predMatrixMap(path->source, current));
+        if (path->predMatrixMap(path->source, current) == INVALID) 
+          current = INVALID;
+        return *this;
+      }
+
+      bool operator==(const RevArcIt& e) const { 
+        return current == e.current; 
+      }
+
+      bool operator!=(const RevArcIt& e) const {
+        return current != e.current; 
+      }
+
+      bool operator<(const RevArcIt& e) const { 
+        return current < e.current; 
+      }
+      
+    private:
+      const PredMatrixMapPath* path;
+      typename Digraph::Node current;
+    };
+
+  private:
+    const Digraph& digraph;
+    const PredMatrixMap& predMatrixMap;
+    typename Digraph::Node source;
+    typename Digraph::Node target;
+  };
+
+}
+
+#endif
Index: lemon/concepts/graph.h
===================================================================
--- lemon/concepts/graph.h	(revision 61)
+++ lemon/concepts/graph.h	(revision 78)
@@ -64,5 +64,5 @@
     /// the EdgeMap to map values for the edges. The InArcIt and
     /// OutArcIt iterates on the same edges but with opposite
-    /// direction. The IncArcIt iterates also on the same edges
+    /// direction. The IncEdgeIt iterates also on the same edges
     /// as the OutArcIt and InArcIt but it is not convertible to Arc just
     /// to Edge.  
@@ -271,39 +271,39 @@
       ///\code
       /// int count=0;
-      /// for(Graph::IncArcIt e(g, n); e!=INVALID; ++e) ++count;
+      /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
       ///\endcode
-      class IncArcIt : public Edge {
-      public:
-        /// Default constructor
-
-        /// @warning The default constructor sets the iterator
-        /// to an undefined value.
-        IncArcIt() { }
-        /// Copy constructor.
-
-        /// Copy constructor.
-        ///
-        IncArcIt(const IncArcIt& e) : Edge(e) { }
-        /// Initialize the iterator to be invalid.
-
-        /// Initialize the iterator to be invalid.
-        ///
-        IncArcIt(Invalid) { }
+      class IncEdgeIt : public Edge {
+      public:
+        /// Default constructor
+
+        /// @warning The default constructor sets the iterator
+        /// to an undefined value.
+        IncEdgeIt() { }
+        /// Copy constructor.
+
+        /// Copy constructor.
+        ///
+        IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
+        /// Initialize the iterator to be invalid.
+
+        /// Initialize the iterator to be invalid.
+        ///
+        IncEdgeIt(Invalid) { }
         /// This constructor sets the iterator to first incident arc.
     
         /// This constructor set the iterator to the first incident arc of
         /// the node.
-        IncArcIt(const Graph&, const Node&) { }
-        /// Edge -> IncArcIt conversion
+        IncEdgeIt(const Graph&, const Node&) { }
+        /// Edge -> IncEdgeIt conversion
 
         /// Sets the iterator to the value of the trivial iterator \c e.
         /// This feature necessitates that each time we 
         /// iterate the arc-set, the iteration order is the same.
-        IncArcIt(const Graph&, const Edge&) { }
+        IncEdgeIt(const Graph&, const Edge&) { }
         /// Next incident arc
 
         /// Assign the iterator to the next incident arc
 	/// of the corresponding node.
-        IncArcIt& operator++() { return *this; }
+        IncEdgeIt& operator++() { return *this; }
       };
 
@@ -721,5 +721,5 @@
       ///
       /// Returns the base node of the iterator
-      Node baseNode(IncArcIt) const {
+      Node baseNode(IncEdgeIt) const {
 	return INVALID;
       }
@@ -728,5 +728,5 @@
       ///
       /// Returns the running node of the iterator
-      Node runningNode(IncArcIt) const {
+      Node runningNode(IncEdgeIt) const {
 	return INVALID;
       }
Index: lemon/concepts/graph_components.h
===================================================================
--- lemon/concepts/graph_components.h	(revision 57)
+++ lemon/concepts/graph_components.h	(revision 78)
@@ -829,14 +829,14 @@
       /// This iterator goes trough the incident arcs of a certain
       /// node of a graph.
-      typedef GraphIncIt<Graph, Edge, Node, 'u'> IncArcIt;
+      typedef GraphIncIt<Graph, Edge, Node, 'u'> IncEdgeIt;
       /// \brief The base node of the iterator.
       ///
       /// Gives back the base node of the iterator.
-      Node baseNode(const IncArcIt&) const { return INVALID; }
+      Node baseNode(const IncEdgeIt&) const { return INVALID; }
 
       /// \brief The running node of the iterator.
       ///
       /// Gives back the running node of the iterator.
-      Node runningNode(const IncArcIt&) const { return INVALID; }
+      Node runningNode(const IncEdgeIt&) const { return INVALID; }
 
       /// @}
@@ -866,8 +866,8 @@
               typename _Graph::EdgeIt >();
             checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, 
-              typename _Graph::Node, 'u'>, typename _Graph::IncArcIt>();
+              typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>();
             
             typename _Graph::Node n;
-            typename _Graph::IncArcIt ueit(INVALID);
+            typename _Graph::IncEdgeIt ueit(INVALID);
             n = graph.baseNode(ueit);
             n = graph.runningNode(ueit);
Index: lemon/concepts/heap.h
===================================================================
--- lemon/concepts/heap.h	(revision 100)
+++ lemon/concepts/heap.h	(revision 100)
@@ -0,0 +1,226 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+///\ingroup concept
+///\file
+///\brief Classes for representing heaps.
+///
+
+#ifndef LEMON_CONCEPT_HEAP_H
+#define LEMON_CONCEPT_HEAP_H
+
+#include <lemon/bits/invalid.h>
+
+namespace lemon {
+  namespace concepts {
+    /// \addtogroup concept
+    /// @{
+
+
+    /// \brief A concept structure describes the main interface of heaps.
+    ///
+    /// A concept structure describes the main interface of heaps.
+    ///
+    template <typename Prio, typename ItemIntMap>
+    class Heap {
+    public:
+
+      ///\brief Type of the items stored in the heap.
+      typedef typename ItemIntMap::Key  Item;
+  
+
+      /// \brief Type to represent the items states.
+      ///
+      /// Each Item element have a state associated to it. It may be "in heap",
+      /// "pre heap" or "post heap". The later two are indifferent from the
+      /// heap's point of view, but may be useful to the user.
+      ///
+      /// The ItemIntMap _should_ be initialized in such way, that it maps
+      /// PRE_HEAP (-1) to any element to be put in the heap...
+      enum State {
+	IN_HEAP = 0,
+	PRE_HEAP = -1,
+	POST_HEAP = -2
+      };
+      
+      /// \brief The constructor.
+      ///
+      /// The constructor.
+      /// \param _iim should be given to the constructor, since it is used
+      /// internally to handle the cross references. The value of the map
+      /// should be PRE_HEAP (-1) for each element.
+      explicit Heap(ItemIntMap &_iim) {}
+
+      /// \brief The number of items stored in the heap.
+      ///
+      /// Returns the number of items stored in the heap.
+      int size() const { return 0; }
+
+      /// \brief Checks if the heap stores no items.
+      ///
+      /// Returns \c true if and only if the heap stores no items.
+      bool empty() const { return false; }
+
+      /// \brief Makes empty this heap.
+      ///
+      /// Makes this heap empty.
+      void clear();
+
+      /// \brief Insert an item into the heap with the given heap.
+      ///    
+      /// Adds \c i to the heap with priority \c p. 
+      /// \param i The item to insert.
+      /// \param p The priority of the item.
+      void push(const Item &i, const Prio &p) {}
+
+      /// \brief Returns the item with minimum priority.
+      ///
+      /// This method returns the item with minimum priority.  
+      /// \pre The heap must be nonempty.  
+      Item top() const {}
+
+      /// \brief Returns the minimum priority.
+      ///
+      /// It returns the minimum priority.
+      /// \pre The heap must be nonempty.
+      Prio prio() const {}
+
+      /// \brief Deletes the item with minimum priority.
+      ///
+      /// This method deletes the item with minimum priority.
+      /// \pre The heap must be non-empty.  
+      void pop() {}
+
+      /// \brief Deletes \c i from the heap.
+      ///
+      /// This method deletes item \c i from the heap, if \c i was
+      /// already stored in the heap.
+      /// \param i The item to erase. 
+      void erase(const Item &i) {}
+
+      /// \brief Returns the priority of \c i.
+      ///
+      /// This function returns the priority of item \c i.  
+      /// \pre \c i must be in the heap.
+      /// \param i The item.
+      Prio operator[](const Item &i) const {}
+
+      /// \brief \c i gets to the heap with priority \c p independently 
+      /// if \c i was already there.
+      ///
+      /// This method calls \ref push(\c i, \c p) if \c i is not stored
+      /// in the heap and sets the priority of \c i to \c p otherwise.
+      /// It may throw an \e UnderFlowPriorityException. 
+      /// \param i The item.
+      /// \param p The priority.
+      void set(const Item &i, const Prio &p) {}
+      
+      /// \brief Decreases the priority of \c i to \c p.
+      ///
+      /// This method decreases the priority of item \c i to \c p.
+      /// \pre \c i must be stored in the heap with priority at least \c p.
+      /// \param i The item.
+      /// \param p The priority.
+      void decrease(const Item &i, const Prio &p) {}
+
+      /// \brief Increases the priority of \c i to \c p.
+      ///
+      /// This method sets the priority of item \c i to \c p. 
+      /// \pre \c i must be stored in the heap with priority at most \c
+      /// p relative to \c Compare.
+      /// \param i The item.
+      /// \param p The priority.
+      void increase(const Item &i, const Prio &p) {}
+
+      /// \brief Returns if \c item is in, has already been in, or has 
+      /// never been in the heap.
+      ///
+      /// This method returns PRE_HEAP if \c item has never been in the
+      /// heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
+      /// otherwise. In the latter case it is possible that \c item will
+      /// get back to the heap again.
+      /// \param i The item.
+      State state(const Item &i) const {}
+
+      /// \brief Sets the state of the \c item in the heap.
+      ///
+      /// Sets the state of the \c item in the heap. It can be used to
+      /// manually clear the heap when it is important to achive the
+      /// better time complexity.
+      /// \param i The item.
+      /// \param st The state. It should not be \c IN_HEAP. 
+      void state(const Item& i, State st) {}
+
+
+      template <typename _Heap>
+      struct Constraints {
+      public:
+    
+	void constraints() {
+	  Item item;
+	  Prio prio;
+
+	  item=Item();
+	  prio=Prio();
+
+	  ignore_unused_variable_warning(item);
+	  ignore_unused_variable_warning(prio);
+
+	  typedef typename _Heap::State State;
+	  State state;
+
+	  ignore_unused_variable_warning(state);
+      
+	  _Heap heap1 = _Heap(map);
+
+	  ignore_unused_variable_warning(heap1);
+      
+	  heap.push(item, prio);
+
+	  prio = heap.prio();
+	  item = heap.top();
+
+	  heap.pop();
+
+	  heap.set(item, prio);
+	  heap.decrease(item, prio);
+	  heap.increase(item, prio);
+	  prio = heap[item];
+
+	  heap.erase(item);
+
+	  state = heap.state(item);
+
+	  state = _Heap::PRE_HEAP;
+	  state = _Heap::IN_HEAP;
+	  state = _Heap::POST_HEAP;
+
+	  heap.clear();
+	}
+    
+	_Heap& heap;
+	ItemIntMap& map;
+
+	Constraints() : heap(0), map(0) {}
+      };
+    };
+
+    /// @}
+  } // namespace lemon
+}
+#endif // LEMON_CONCEPT_PATH_H
Index: lemon/concepts/maps.h
===================================================================
--- lemon/concepts/maps.h	(revision 74)
+++ lemon/concepts/maps.h	(revision 94)
@@ -30,5 +30,5 @@
 
   namespace concepts {
-  
+
     /// \addtogroup concept
     /// @{
@@ -43,14 +43,12 @@
     public:
       /// The key type of the map.
-      typedef K Key;    
-      /// The value type of the map. (The type of objects associated with the keys).
-      typedef T Value;
-
-      /// Returns the value associated with a key.
-
-      /// Returns the value associated with a key.
-      /// \bug Value shouldn't need to be default constructible.
-      ///
-      Value operator[](const Key &) const {return Value();}
+      typedef K Key;
+      /// The value type of the map. (The type of objects associated with the keys).
+      typedef T Value;
+
+      /// Returns the value associated with the given key.
+      Value operator[](const Key &) const { 
+        return *static_cast<Value *>(0);
+      }
 
       template<typename _ReadMap>
@@ -59,44 +57,7 @@
 	  Value val = m[key];
 	  val = m[key];
-	  typename _ReadMap::Value own_val = m[own_key]; 
-	  own_val = m[own_key]; 
-
-	  ignore_unused_variable_warning(val);
-	  ignore_unused_variable_warning(own_val);
-	  ignore_unused_variable_warning(key);
-	}
-	Key& key;
-	typename _ReadMap::Key& own_key;
-	_ReadMap& m;
-      };
-      
-    };
-
-
-    /// Writable map concept
-    
-    /// Writable map concept.
-    ///
-    template<typename K, typename T>
-    class WriteMap
-    {
-    public:
-      /// The key type of the map.
-      typedef K Key;    
-      /// The value type of the map. (The type of objects associated with the keys).
-      typedef T Value;
-
-      /// Sets the value associated with a key.
-      void set(const Key &,const Value &) {}
-
-      ///Default constructor
-      WriteMap() {}
-
-      template <typename _WriteMap>
-      struct Constraints {
-	void constraints() {
-	  // No constraints for constructor.
-	  m.set(key, val);
-	  m.set(own_key, own_val);
+	  typename _ReadMap::Value own_val = m[own_key];
+	  own_val = m[own_key];
+
 	  ignore_unused_variable_warning(key);
 	  ignore_unused_variable_warning(val);
@@ -104,16 +65,52 @@
 	  ignore_unused_variable_warning(own_val);
 	}
-
-	Value& val;
-	typename _WriteMap::Value own_val;
-	Key& key;
-	typename _WriteMap::Key& own_key;
+	const Key& key;
+	const typename _ReadMap::Key& own_key;
+	const _ReadMap& m;
+      };
+
+    };
+
+
+    /// Writable map concept
+
+    /// Writable map concept.
+    ///
+    template<typename K, typename T>
+    class WriteMap
+    {
+    public:
+      /// The key type of the map.
+      typedef K Key;
+      /// The value type of the map. (The type of objects associated with the keys).
+      typedef T Value;
+
+      /// Sets the value associated with the given key.
+      void set(const Key &, const Value &) {}
+
+      /// Default constructor.
+      WriteMap() {}
+
+      template <typename _WriteMap>
+      struct Constraints {
+	void constraints() {
+	  m.set(key, val);
+	  m.set(own_key, own_val);
+
+	  ignore_unused_variable_warning(key);
+	  ignore_unused_variable_warning(val);
+	  ignore_unused_variable_warning(own_key);
+	  ignore_unused_variable_warning(own_val);
+	}
+	const Key& key;
+	const Value& val;
+	const typename _WriteMap::Key& own_key;
+	const typename _WriteMap::Value own_val;
 	_WriteMap& m;
-
       };
     };
 
     /// Read/writable map concept
-    
+
     /// Read/writable map concept.
     ///
@@ -124,12 +121,15 @@
     public:
       /// The key type of the map.
-      typedef K Key;    
-      /// The value type of the map. (The type of objects associated with the keys).
-      typedef T Value;
-
-      /// Returns the value associated with a key.
-      Value operator[](const Key &) const {return Value();}
-      /// Sets the value associated with a key.
-      void set(const Key & ,const Value &) {}
+      typedef K Key;
+      /// The value type of the map. (The type of objects associated with the keys).
+      typedef T Value;
+
+      /// Returns the value associated with the given key.
+      Value operator[](const Key &) const { 
+        return *static_cast<Value *>(0);
+      }
+
+      /// Sets the value associated with the given key.
+      void set(const Key &, const Value &) {}
 
       template<typename _ReadWriteMap>
@@ -141,11 +141,10 @@
       };
     };
-  
-  
+
+
     /// Dereferable map concept
-    
+
     /// Dereferable map concept.
     ///
-    /// \todo Rethink this concept.
     template<typename K, typename T, typename R, typename CR>
     class ReferenceMap : public ReadWriteMap<K,T>
@@ -155,5 +154,5 @@
       typedef True ReferenceMapTag;
       /// The key type of the map.
-      typedef K Key;    
+      typedef K Key;
       /// The value type of the map. (The type of objects associated with the keys).
       typedef T Value;
@@ -163,13 +162,17 @@
       typedef CR ConstReference;
 
-    protected:
-      Value tmp;
-    public:
-
-      ///Returns a reference to the value associated with a key.
-      Reference operator[](const Key &) { return tmp; }
-      ///Returns a const reference to the value associated with a key.
-      ConstReference operator[](const Key &) const { return tmp; }
-      /// Sets the value associated with a key.
+    public:
+
+      /// Returns a reference to the value associated with the given key.
+      Reference operator[](const Key &) { 
+        return *static_cast<Value *>(0);
+      }
+
+      /// Returns a const reference to the value associated with the given key.
+      ConstReference operator[](const Key &) const {
+        return *static_cast<Value *>(0);
+      }
+
+      /// Sets the value associated with the given key.
       void set(const Key &k,const Value &t) { operator[](k)=t; }
 
@@ -178,20 +181,23 @@
 	void constraints() {
 	  checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
+	  ref = m[key];
 	  m[key] = val;
-	  val  = m[key];
 	  m[key] = ref;
-	  ref = m[key];
+	  m[key] = cref;
+	  own_ref = m[own_key];
 	  m[own_key] = own_val;
-	  own_val  = m[own_key];
 	  m[own_key] = own_ref;
-	  own_ref = m[own_key];	  	  
-	}
-
-	typename _ReferenceMap::Key& own_key;
+	  m[own_key] = own_cref;
+	  m[key] = m[own_key];
+	  m[own_key] = m[key];
+	}
+	const Key& key;
+	Value& val;
+	Reference ref;
+	ConstReference cref;
+	const typename _ReferenceMap::Key& own_key;
 	typename _ReferenceMap::Value& own_val;
 	typename _ReferenceMap::Reference own_ref;
-	Key& key;
-	Value& val;
-	Reference ref;
+	typename _ReferenceMap::ConstReference own_cref;
 	_ReferenceMap& m;
       };
Index: lemon/concepts/path.h
===================================================================
--- lemon/concepts/path.h	(revision 96)
+++ lemon/concepts/path.h	(revision 96)
@@ -0,0 +1,307 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+///\ingroup concept
+///\file
+///\brief Classes for representing paths in digraphs.
+///
+///\todo Iterators have obsolete style
+
+#ifndef LEMON_CONCEPT_PATH_H
+#define LEMON_CONCEPT_PATH_H
+
+#include <lemon/bits/invalid.h>
+#include <lemon/bits/utility.h>
+#include <lemon/concept_check.h>
+
+namespace lemon {
+  namespace concepts {
+
+    /// \addtogroup concept
+    /// @{
+
+    /// \brief A skeleton structure for representing directed paths in
+    /// a digraph.
+    ///
+    /// A skeleton structure for representing directed paths in a
+    /// digraph.  
+    /// \param _Digraph The digraph type in which the path is.
+    ///
+    /// In a sense, the path can be treated as a list of arcs. The
+    /// lemon path type stores just this list. As a consequence it
+    /// cannot enumerate the nodes in the path and the zero length
+    /// paths cannot store the source.
+    ///
+    template <typename _Digraph>
+    class Path {
+    public:
+
+      /// Type of the underlying digraph.
+      typedef _Digraph Digraph;
+      /// Arc type of the underlying digraph.
+      typedef typename Digraph::Arc Arc;
+
+      class ArcIt;
+
+      /// \brief Default constructor
+      Path() {}
+
+      /// \brief Template constructor
+      template <typename CPath>
+      Path(const CPath& cpath) {}
+
+      /// \brief Template assigment
+      template <typename CPath>
+      Path& operator=(const CPath& cpath) {}
+
+      /// Length of the path ie. the number of arcs in the path.
+      int length() const { return 0;}
+
+      /// Returns whether the path is empty.
+      bool empty() const { return true;}
+
+      /// Resets the path to an empty path.
+      void clear() {}
+
+      /// \brief Lemon style iterator for path arcs
+      ///
+      /// This class is used to iterate on the arcs of the paths.
+      class ArcIt {
+      public:
+	/// Default constructor
+	ArcIt() {}
+	/// Invalid constructor
+	ArcIt(Invalid) {}
+	/// Constructor for first arc
+	ArcIt(const Path &) {}
+
+        /// Conversion to Arc
+	operator Arc() const { return INVALID; }
+
+	/// Next arc
+	ArcIt& operator++() {return *this;}
+
+	/// Comparison operator
+	bool operator==(const ArcIt&) const {return true;}
+	/// Comparison operator
+	bool operator!=(const ArcIt&) const {return true;}
+ 	/// Comparison operator
+ 	bool operator<(const ArcIt&) const {return false;}
+
+      };
+
+      template <typename _Path>
+      struct Constraints {
+        void constraints() {
+          Path<Digraph> pc;
+          _Path p, pp(pc);
+          int l = p.length();
+          int e = p.empty();
+          p.clear();
+
+          p = pc;
+
+          typename _Path::ArcIt id, ii(INVALID), i(p);
+
+          ++i;
+          typename Digraph::Arc ed = i;
+
+          e = (i == ii);
+          e = (i != ii);
+          e = (i < ii);
+
+          ignore_unused_variable_warning(l);
+          ignore_unused_variable_warning(pp);
+          ignore_unused_variable_warning(e);
+          ignore_unused_variable_warning(id);
+          ignore_unused_variable_warning(ii);
+          ignore_unused_variable_warning(ed);
+        }
+      };
+
+    };
+
+    namespace _path_bits {
+      
+      template <typename _Digraph, typename _Path, typename RevPathTag = void>
+      struct PathDumperConstraints {
+        void constraints() {
+          int l = p.length();
+          int e = p.empty();
+
+          typename _Path::ArcIt id, i(p);
+
+          ++i;
+          typename _Digraph::Arc ed = i;
+
+          e = (i == INVALID);
+          e = (i != INVALID);
+
+          ignore_unused_variable_warning(l);
+          ignore_unused_variable_warning(e);
+          ignore_unused_variable_warning(id);
+          ignore_unused_variable_warning(ed);
+        }
+        _Path& p;
+      };
+
+      template <typename _Digraph, typename _Path>
+      struct PathDumperConstraints<
+        _Digraph, _Path, 
+        typename enable_if<typename _Path::RevPathTag, void>::type
+      > {
+        void constraints() {
+          int l = p.length();
+          int e = p.empty();
+
+          typename _Path::RevArcIt id, i(p);
+
+          ++i;
+          typename _Digraph::Arc ed = i;
+
+          e = (i == INVALID);
+          e = (i != INVALID);
+
+          ignore_unused_variable_warning(l);
+          ignore_unused_variable_warning(e);
+          ignore_unused_variable_warning(id);
+          ignore_unused_variable_warning(ed);
+        }
+        _Path& p;
+      };
+    
+    }
+
+
+    /// \brief A skeleton structure for path dumpers.
+    ///
+    /// A skeleton structure for path dumpers. The path dumpers are
+    /// the generalization of the paths. The path dumpers can
+    /// enumerate the arcs of the path wheter in forward or in
+    /// backward order.  In most time these classes are not used
+    /// directly rather it used to assign a dumped class to a real
+    /// path type.
+    ///
+    /// The main purpose of this concept is that the shortest path
+    /// algorithms can enumerate easily the arcs in reverse order.
+    /// If we would like to give back a real path from these
+    /// algorithms then we should create a temporarly path object. In
+    /// Lemon such algorithms gives back a path dumper what can
+    /// assigned to a real path and the dumpers can be implemented as
+    /// an adaptor class to the predecessor map.
+
+    /// \param _Digraph  The digraph type in which the path is.
+    ///
+    /// The paths can be constructed from any path type by a
+    /// template constructor or a template assignment operator.
+    /// 
+    template <typename _Digraph>
+    class PathDumper {
+    public:
+
+      /// Type of the underlying digraph.
+      typedef _Digraph Digraph;
+      /// Arc type of the underlying digraph.
+      typedef typename Digraph::Arc Arc;
+
+      /// Length of the path ie. the number of arcs in the path.
+      int length() const { return 0;}
+
+      /// Returns whether the path is empty.
+      bool empty() const { return true;}
+
+      /// \brief Forward or reverse dumping
+      ///
+      /// If the RevPathTag is defined and true then reverse dumping
+      /// is provided in the path dumper. In this case instead of the
+      /// ArcIt the RevArcIt iterator should be implemented in the
+      /// dumper.
+      typedef False RevPathTag;
+
+      /// \brief Lemon style iterator for path arcs
+      ///
+      /// This class is used to iterate on the arcs of the paths.
+      class ArcIt {
+      public:
+	/// Default constructor
+	ArcIt() {}
+	/// Invalid constructor
+	ArcIt(Invalid) {}
+	/// Constructor for first arc
+	ArcIt(const PathDumper&) {}
+
+        /// Conversion to Arc
+	operator Arc() const { return INVALID; }
+
+	/// Next arc
+	ArcIt& operator++() {return *this;}
+
+	/// Comparison operator
+	bool operator==(const ArcIt&) const {return true;}
+	/// Comparison operator
+	bool operator!=(const ArcIt&) const {return true;}
+ 	/// Comparison operator
+ 	bool operator<(const ArcIt&) const {return false;}
+
+      };
+
+      /// \brief Lemon style iterator for path arcs
+      ///
+      /// This class is used to iterate on the arcs of the paths in
+      /// reverse direction.
+      class RevArcIt {
+      public:
+	/// Default constructor
+	RevArcIt() {}
+	/// Invalid constructor
+	RevArcIt(Invalid) {}
+	/// Constructor for first arc
+	RevArcIt(const PathDumper &) {}
+
+        /// Conversion to Arc
+	operator Arc() const { return INVALID; }
+
+	/// Next arc
+	RevArcIt& operator++() {return *this;}
+
+	/// Comparison operator
+	bool operator==(const RevArcIt&) const {return true;}
+	/// Comparison operator
+	bool operator!=(const RevArcIt&) const {return true;}
+ 	/// Comparison operator
+ 	bool operator<(const RevArcIt&) const {return false;}
+
+      };
+
+      template <typename _Path>
+      struct Constraints {
+        void constraints() {
+          function_requires<_path_bits::
+            PathDumperConstraints<Digraph, _Path> >();
+        }
+      };
+
+    };
+
+
+    ///@}
+  }
+
+} // namespace lemon
+
+#endif // LEMON_CONCEPT_PATH_H
Index: lemon/dfs.h
===================================================================
--- lemon/dfs.h	(revision 100)
+++ lemon/dfs.h	(revision 100)
@@ -0,0 +1,1543 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_DFS_H
+#define LEMON_DFS_H
+
+///\ingroup search
+///\file
+///\brief Dfs algorithm.
+
+#include <lemon/list_graph.h>
+#include <lemon/graph_utils.h>
+#include <lemon/bits/path_dump.h>
+#include <lemon/bits/invalid.h>
+#include <lemon/error.h>
+#include <lemon/maps.h>
+
+#include <lemon/concept_check.h>
+
+namespace lemon {
+
+  
+  ///Default traits class of Dfs class.
+
+  ///Default traits class of Dfs class.
+  ///\param GR Digraph type.
+  template<class GR>
+  struct DfsDefaultTraits
+  {
+    ///The digraph type the algorithm runs on. 
+    typedef GR Digraph;
+    ///\brief The type of the map that stores the last
+    ///arcs of the %DFS paths.
+    /// 
+    ///The type of the map that stores the last
+    ///arcs of the %DFS paths.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
+    ///Instantiates a PredMap.
+ 
+    ///This function instantiates a \ref PredMap. 
+    ///\param G is the digraph, to which we would like to define the PredMap.
+    ///\todo The digraph alone may be insufficient to initialize
+    static PredMap *createPredMap(const GR &G) 
+    {
+      return new PredMap(G);
+    }
+
+    ///The type of the map that indicates which nodes are processed.
+ 
+    ///The type of the map that indicates which nodes are processed.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
+    ///Instantiates a ProcessedMap.
+ 
+    ///This function instantiates a \ref ProcessedMap. 
+    ///\param g is the digraph, to which
+    ///we would like to define the \ref ProcessedMap
+#ifdef DOXYGEN
+    static ProcessedMap *createProcessedMap(const GR &g)
+#else
+    static ProcessedMap *createProcessedMap(const GR &)
+#endif
+    {
+      return new ProcessedMap();
+    }
+    ///The type of the map that indicates which nodes are reached.
+ 
+    ///The type of the map that indicates which nodes are reached.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef typename Digraph::template NodeMap<bool> ReachedMap;
+    ///Instantiates a ReachedMap.
+ 
+    ///This function instantiates a \ref ReachedMap. 
+    ///\param G is the digraph, to which
+    ///we would like to define the \ref ReachedMap.
+    static ReachedMap *createReachedMap(const GR &G)
+    {
+      return new ReachedMap(G);
+    }
+    ///The type of the map that stores the dists of the nodes.
+ 
+    ///The type of the map that stores the dists of the nodes.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef typename Digraph::template NodeMap<int> DistMap;
+    ///Instantiates a DistMap.
+ 
+    ///This function instantiates a \ref DistMap. 
+    ///\param G is the digraph, to which we would like to define the \ref DistMap
+    static DistMap *createDistMap(const GR &G)
+    {
+      return new DistMap(G);
+    }
+  };
+  
+  ///%DFS algorithm class.
+  
+  ///\ingroup search
+  ///This class provides an efficient implementation of the %DFS algorithm.
+  ///
+  ///\param GR The digraph type the algorithm runs on. The default value is
+  ///\ref ListDigraph. The value of GR is not used directly by Dfs, it
+  ///is only passed to \ref DfsDefaultTraits.
+  ///\param TR Traits class to set various data types used by the algorithm.
+  ///The default traits class is
+  ///\ref DfsDefaultTraits "DfsDefaultTraits<GR>".
+  ///See \ref DfsDefaultTraits for the documentation of
+  ///a Dfs traits class.
+  ///
+  ///\author Jacint Szabo and Alpar Juttner
+#ifdef DOXYGEN
+  template <typename GR,
+	    typename TR>
+#else
+  template <typename GR=ListDigraph,
+	    typename TR=DfsDefaultTraits<GR> >
+#endif
+  class Dfs {
+  public:
+    /**
+     * \brief \ref Exception for uninitialized parameters.
+     *
+     * This error represents problems in the initialization
+     * of the parameters of the algorithms.
+     */
+    class UninitializedParameter : public lemon::UninitializedParameter {
+    public:
+      virtual const char* what() const throw() {
+	return "lemon::Dfs::UninitializedParameter";
+      }
+    };
+
+    typedef TR Traits;
+    ///The type of the underlying digraph.
+    typedef typename TR::Digraph Digraph;
+    ///\e
+    typedef typename Digraph::Node Node;
+    ///\e
+    typedef typename Digraph::NodeIt NodeIt;
+    ///\e
+    typedef typename Digraph::Arc Arc;
+    ///\e
+    typedef typename Digraph::OutArcIt OutArcIt;
+    
+    ///\brief The type of the map that stores the last
+    ///arcs of the %DFS paths.
+    typedef typename TR::PredMap PredMap;
+    ///The type of the map indicating which nodes are reached.
+    typedef typename TR::ReachedMap ReachedMap;
+    ///The type of the map indicating which nodes are processed.
+    typedef typename TR::ProcessedMap ProcessedMap;
+    ///The type of the map that stores the dists of the nodes.
+    typedef typename TR::DistMap DistMap;
+  private:
+    /// Pointer to the underlying digraph.
+    const Digraph *G;
+    ///Pointer to the map of predecessors arcs.
+    PredMap *_pred;
+    ///Indicates if \ref _pred is locally allocated (\c true) or not.
+    bool local_pred;
+    ///Pointer to the map of distances.
+    DistMap *_dist;
+    ///Indicates if \ref _dist is locally allocated (\c true) or not.
+    bool local_dist;
+    ///Pointer to the map of reached status of the nodes.
+    ReachedMap *_reached;
+    ///Indicates if \ref _reached is locally allocated (\c true) or not.
+    bool local_reached;
+    ///Pointer to the map of processed status of the nodes.
+    ProcessedMap *_processed;
+    ///Indicates if \ref _processed is locally allocated (\c true) or not.
+    bool local_processed;
+
+    std::vector<typename Digraph::OutArcIt> _stack;
+    int _stack_head;
+
+    ///Creates the maps if necessary.
+    
+    ///\todo Better memory allocation (instead of new).
+    void create_maps() 
+    {
+      if(!_pred) {
+	local_pred = true;
+	_pred = Traits::createPredMap(*G);
+      }
+      if(!_dist) {
+	local_dist = true;
+	_dist = Traits::createDistMap(*G);
+      }
+      if(!_reached) {
+	local_reached = true;
+	_reached = Traits::createReachedMap(*G);
+      }
+      if(!_processed) {
+	local_processed = true;
+	_processed = Traits::createProcessedMap(*G);
+      }
+    }
+
+  protected:
+
+    Dfs() {}
+    
+  public:
+
+    typedef Dfs Create;
+
+    ///\name Named template parameters
+
+    ///@{
+
+    template <class T>
+    struct DefPredMapTraits : public Traits {
+      typedef T PredMap;
+      static PredMap *createPredMap(const Digraph &G) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///PredMap type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting PredMap type
+    ///
+    template <class T>
+    struct DefPredMap : public Dfs<Digraph, DefPredMapTraits<T> > {
+      typedef Dfs<Digraph, DefPredMapTraits<T> > Create;
+    };
+    
+    
+    template <class T>
+    struct DefDistMapTraits : public Traits {
+      typedef T DistMap;
+      static DistMap *createDistMap(const Digraph &) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///DistMap type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting DistMap
+    ///type
+    template <class T>
+    struct DefDistMap {
+      typedef Dfs<Digraph, DefDistMapTraits<T> > Create;
+    };
+    
+    template <class T>
+    struct DefReachedMapTraits : public Traits {
+      typedef T ReachedMap;
+      static ReachedMap *createReachedMap(const Digraph &) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///ReachedMap type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting ReachedMap type
+    ///
+    template <class T>
+    struct DefReachedMap : public Dfs< Digraph, DefReachedMapTraits<T> > {
+      typedef Dfs< Digraph, DefReachedMapTraits<T> > Create;
+    };
+
+    template <class T>
+    struct DefProcessedMapTraits : public Traits {
+      typedef T ProcessedMap;
+      static ProcessedMap *createProcessedMap(const Digraph &) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///ProcessedMap type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
+    ///
+    template <class T>
+    struct DefProcessedMap : public Dfs< Digraph, DefProcessedMapTraits<T> > { 
+      typedef Dfs< Digraph, DefProcessedMapTraits<T> > Create;
+    };
+    
+    struct DefDigraphProcessedMapTraits : public Traits {
+      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
+      static ProcessedMap *createProcessedMap(const Digraph &G) 
+      {
+	return new ProcessedMap(G);
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter"
+    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
+    ///
+    ///\ref named-templ-param "Named parameter"
+    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
+    ///If you don't set it explicitely, it will be automatically allocated.
+    template <class T>
+    class DefProcessedMapToBeDefaultMap :
+      public Dfs< Digraph, DefDigraphProcessedMapTraits> { 
+      typedef Dfs< Digraph, DefDigraphProcessedMapTraits> Create;
+    };
+    
+    ///@}
+
+  public:      
+    
+    ///Constructor.
+    
+    ///\param _G the digraph the algorithm will run on.
+    ///
+    Dfs(const Digraph& _G) :
+      G(&_G),
+      _pred(NULL), local_pred(false),
+      _dist(NULL), local_dist(false),
+      _reached(NULL), local_reached(false),
+      _processed(NULL), local_processed(false)
+    { }
+    
+    ///Destructor.
+    ~Dfs() 
+    {
+      if(local_pred) delete _pred;
+      if(local_dist) delete _dist;
+      if(local_reached) delete _reached;
+      if(local_processed) delete _processed;
+    }
+
+    ///Sets the map storing the predecessor arcs.
+
+    ///Sets the map storing the predecessor arcs.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destuctor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Dfs &predMap(PredMap &m) 
+    {
+      if(local_pred) {
+	delete _pred;
+	local_pred=false;
+      }
+      _pred = &m;
+      return *this;
+    }
+
+    ///Sets the map storing the distances calculated by the algorithm.
+
+    ///Sets the map storing the distances calculated by the algorithm.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destuctor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Dfs &distMap(DistMap &m) 
+    {
+      if(local_dist) {
+	delete _dist;
+	local_dist=false;
+      }
+      _dist = &m;
+      return *this;
+    }
+
+    ///Sets the map indicating if a node is reached.
+
+    ///Sets the map indicating if a node is reached.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destuctor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Dfs &reachedMap(ReachedMap &m) 
+    {
+      if(local_reached) {
+	delete _reached;
+	local_reached=false;
+      }
+      _reached = &m;
+      return *this;
+    }
+
+    ///Sets the map indicating if a node is processed.
+
+    ///Sets the map indicating if a node is processed.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destuctor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Dfs &processedMap(ProcessedMap &m) 
+    {
+      if(local_processed) {
+	delete _processed;
+	local_processed=false;
+      }
+      _processed = &m;
+      return *this;
+    }
+
+  public:
+    ///\name Execution control
+    ///The simplest way to execute the algorithm is to use
+    ///one of the member functions called \c run(...).
+    ///\n
+    ///If you need more control on the execution,
+    ///first you must call \ref init(), then you can add a source node
+    ///with \ref addSource().
+    ///Finally \ref start() will perform the actual path
+    ///computation.
+
+    ///@{
+
+    ///Initializes the internal data structures.
+
+    ///Initializes the internal data structures.
+    ///
+    void init()
+    {
+      create_maps();
+      _stack.resize(countNodes(*G));
+      _stack_head=-1;
+      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
+	_pred->set(u,INVALID);
+	// _predNode->set(u,INVALID);
+	_reached->set(u,false);
+	_processed->set(u,false);
+      }
+    }
+    
+    ///Adds a new source node.
+
+    ///Adds a new source node to the set of nodes to be processed.
+    ///
+    ///\warning dists are wrong (or at least strange)
+    ///in case of multiple sources.
+    void addSource(Node s)
+    {
+      if(!(*_reached)[s])
+	{
+	  _reached->set(s,true);
+	  _pred->set(s,INVALID);
+	  OutArcIt e(*G,s);
+	  if(e!=INVALID) {
+	    _stack[++_stack_head]=e;
+	    _dist->set(s,_stack_head);
+	  }
+	  else {
+	    _processed->set(s,true);
+	    _dist->set(s,0);
+	  }
+	}
+    }
+    
+    ///Processes the next arc.
+
+    ///Processes the next arc.
+    ///
+    ///\return The processed arc.
+    ///
+    ///\pre The stack must not be empty!
+    Arc processNextArc()
+    { 
+      Node m;
+      Arc e=_stack[_stack_head];
+      if(!(*_reached)[m=G->target(e)]) {
+	_pred->set(m,e);
+	_reached->set(m,true);
+	++_stack_head;
+	_stack[_stack_head] = OutArcIt(*G, m);
+	_dist->set(m,_stack_head);
+      }
+      else {
+	m=G->source(e);
+	++_stack[_stack_head];
+      }
+      while(_stack_head>=0 && _stack[_stack_head]==INVALID) {
+	_processed->set(m,true);
+	--_stack_head;
+	if(_stack_head>=0) {
+	  m=G->source(_stack[_stack_head]);
+	  ++_stack[_stack_head];
+	}
+      }
+      return e;
+    }
+    ///Next arc to be processed.
+
+    ///Next arc to be processed.
+    ///
+    ///\return The next arc to be processed or INVALID if the stack is
+    /// empty.
+    OutArcIt nextArc()
+    { 
+      return _stack_head>=0?_stack[_stack_head]:INVALID;
+    }
+
+    ///\brief Returns \c false if there are nodes
+    ///to be processed in the queue
+    ///
+    ///Returns \c false if there are nodes
+    ///to be processed in the queue
+    bool emptyQueue() { return _stack_head<0; }
+    ///Returns the number of the nodes to be processed.
+    
+    ///Returns the number of the nodes to be processed in the queue.
+    int queueSize() { return _stack_head+1; }
+    
+    ///Executes the algorithm.
+
+    ///Executes the algorithm.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///This method runs the %DFS algorithm from the root node(s)
+    ///in order to
+    ///compute the
+    ///%DFS path to each node. The algorithm computes
+    ///- The %DFS tree.
+    ///- The distance of each node from the root(s) in the %DFS tree.
+    ///
+    void start()
+    {
+      while ( !emptyQueue() ) processNextArc();
+    }
+    
+    ///Executes the algorithm until \c dest is reached.
+
+    ///Executes the algorithm until \c dest is reached.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///This method runs the %DFS algorithm from the root node(s)
+    ///in order to
+    ///compute the
+    ///%DFS path to \c dest. The algorithm computes
+    ///- The %DFS path to \c  dest.
+    ///- The distance of \c dest from the root(s) in the %DFS tree.
+    ///
+    void start(Node dest)
+    {
+      while ( !emptyQueue() && G->target(_stack[_stack_head])!=dest ) 
+	processNextArc();
+    }
+    
+    ///Executes the algorithm until a condition is met.
+
+    ///Executes the algorithm until a condition is met.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///\param em must be a bool (or convertible) arc map. The algorithm
+    ///will stop when it reaches an arc \c e with <tt>em[e]</tt> true.
+    ///
+    ///\return The reached arc \c e with <tt>em[e]</tt> true or
+    ///\c INVALID if no such arc was found.
+    ///
+    ///\warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an arc map,
+    ///not a node map.
+    template<class EM>
+    Arc start(const EM &em)
+    {
+      while ( !emptyQueue() && !em[_stack[_stack_head]] )
+        processNextArc();
+      return emptyQueue() ? INVALID : _stack[_stack_head];
+    }
+
+    ///Runs %DFS algorithm to visit all nodes in the digraph.
+    
+    ///This method runs the %DFS algorithm in order to
+    ///compute the
+    ///%DFS path to each node. The algorithm computes
+    ///- The %DFS tree.
+    ///- The distance of each node from the root in the %DFS tree.
+    ///
+    ///\note d.run() is just a shortcut of the following code.
+    ///\code
+    ///  d.init();
+    ///  for (NodeIt it(digraph); it != INVALID; ++it) {
+    ///    if (!d.reached(it)) {
+    ///      d.addSource(it);
+    ///      d.start();
+    ///    }
+    ///  }
+    ///\endcode
+    void run() {
+      init();
+      for (NodeIt it(*G); it != INVALID; ++it) {
+        if (!reached(it)) {
+          addSource(it);
+          start();
+        }
+      }
+    }
+
+    ///Runs %DFS algorithm from node \c s.
+    
+    ///This method runs the %DFS algorithm from a root node \c s
+    ///in order to
+    ///compute the
+    ///%DFS path to each node. The algorithm computes
+    ///- The %DFS tree.
+    ///- The distance of each node from the root in the %DFS tree.
+    ///
+    ///\note d.run(s) is just a shortcut of the following code.
+    ///\code
+    ///  d.init();
+    ///  d.addSource(s);
+    ///  d.start();
+    ///\endcode
+    void run(Node s) {
+      init();
+      addSource(s);
+      start();
+    }
+    
+    ///Finds the %DFS path between \c s and \c t.
+    
+    ///Finds the %DFS path between \c s and \c t.
+    ///
+    ///\return The length of the %DFS s---t path if there exists one,
+    ///0 otherwise.
+    ///\note Apart from the return value, d.run(s,t) is
+    ///just a shortcut of the following code.
+    ///\code
+    ///  d.init();
+    ///  d.addSource(s);
+    ///  d.start(t);
+    ///\endcode
+    int run(Node s,Node t) {
+      init();
+      addSource(s);
+      start(t);
+      return reached(t)?_stack_head+1:0;
+    }
+    
+    ///@}
+
+    ///\name Query Functions
+    ///The result of the %DFS algorithm can be obtained using these
+    ///functions.\n
+    ///Before the use of these functions,
+    ///either run() or start() must be called.
+    
+    ///@{
+
+    typedef PredMapPath<Digraph, PredMap> Path;
+
+    ///Gives back the shortest path.
+    
+    ///Gives back the shortest path.
+    ///\pre The \c t should be reachable from the source.
+    Path path(Node t) 
+    {
+      return Path(*G, *_pred, t);
+    }
+
+    ///The distance of a node from the root(s).
+
+    ///Returns the distance of a node from the root(s).
+    ///\pre \ref run() must be called before using this function.
+    ///\warning If node \c v is unreachable from the root(s) then the return 
+    ///value of this funcion is undefined.
+    int dist(Node v) const { return (*_dist)[v]; }
+
+    ///Returns the 'previous arc' of the %DFS tree.
+
+    ///For a node \c v it returns the 'previous arc'
+    ///of the %DFS path,
+    ///i.e. it returns the last arc of a %DFS path from the root(s) to \c
+    ///v. It is \ref INVALID
+    ///if \c v is unreachable from the root(s) or \c v is a root. The
+    ///%DFS tree used here is equal to the %DFS tree used in
+    ///\ref predNode().
+    ///\pre Either \ref run() or \ref start() must be called before using
+    ///this function.
+    Arc predArc(Node v) const { return (*_pred)[v];}
+
+    ///Returns the 'previous node' of the %DFS tree.
+
+    ///For a node \c v it returns the 'previous node'
+    ///of the %DFS tree,
+    ///i.e. it returns the last but one node from a %DFS path from the
+    ///root(s) to \c v.
+    ///It is INVALID if \c v is unreachable from the root(s) or
+    ///if \c v itself a root.
+    ///The %DFS tree used here is equal to the %DFS
+    ///tree used in \ref predArc().
+    ///\pre Either \ref run() or \ref start() must be called before
+    ///using this function.
+    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
+				  G->source((*_pred)[v]); }
+    
+    ///Returns a reference to the NodeMap of distances.
+
+    ///Returns a reference to the NodeMap of distances.
+    ///\pre Either \ref run() or \ref init() must
+    ///be called before using this function.
+    const DistMap &distMap() const { return *_dist;}
+ 
+    ///Returns a reference to the %DFS arc-tree map.
+
+    ///Returns a reference to the NodeMap of the arcs of the
+    ///%DFS tree.
+    ///\pre Either \ref run() or \ref init()
+    ///must be called before using this function.
+    const PredMap &predMap() const { return *_pred;}
+ 
+    ///Checks if a node is reachable from the root.
+
+    ///Returns \c true if \c v is reachable from the root(s).
+    ///\warning The source nodes are inditated as unreachable.
+    ///\pre Either \ref run() or \ref start()
+    ///must be called before using this function.
+    ///
+    bool reached(Node v) { return (*_reached)[v]; }
+    
+    ///@}
+  };
+
+  ///Default traits class of Dfs function.
+
+  ///Default traits class of Dfs function.
+  ///\param GR Digraph type.
+  template<class GR>
+  struct DfsWizardDefaultTraits
+  {
+    ///The digraph type the algorithm runs on. 
+    typedef GR Digraph;
+    ///\brief The type of the map that stores the last
+    ///arcs of the %DFS paths.
+    /// 
+    ///The type of the map that stores the last
+    ///arcs of the %DFS paths.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap;
+    ///Instantiates a PredMap.
+ 
+    ///This function instantiates a \ref PredMap. 
+    ///\param g is the digraph, to which we would like to define the PredMap.
+    ///\todo The digraph alone may be insufficient to initialize
+#ifdef DOXYGEN
+    static PredMap *createPredMap(const GR &g) 
+#else
+    static PredMap *createPredMap(const GR &) 
+#endif
+    {
+      return new PredMap();
+    }
+
+    ///The type of the map that indicates which nodes are processed.
+ 
+    ///The type of the map that indicates which nodes are processed.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
+    ///Instantiates a ProcessedMap.
+ 
+    ///This function instantiates a \ref ProcessedMap. 
+    ///\param g is the digraph, to which
+    ///we would like to define the \ref ProcessedMap
+#ifdef DOXYGEN
+    static ProcessedMap *createProcessedMap(const GR &g)
+#else
+    static ProcessedMap *createProcessedMap(const GR &)
+#endif
+    {
+      return new ProcessedMap();
+    }
+    ///The type of the map that indicates which nodes are reached.
+ 
+    ///The type of the map that indicates which nodes are reached.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef typename Digraph::template NodeMap<bool> ReachedMap;
+    ///Instantiates a ReachedMap.
+ 
+    ///This function instantiates a \ref ReachedMap. 
+    ///\param G is the digraph, to which
+    ///we would like to define the \ref ReachedMap.
+    static ReachedMap *createReachedMap(const GR &G)
+    {
+      return new ReachedMap(G);
+    }
+    ///The type of the map that stores the dists of the nodes.
+ 
+    ///The type of the map that stores the dists of the nodes.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef NullMap<typename Digraph::Node,int> DistMap;
+    ///Instantiates a DistMap.
+ 
+    ///This function instantiates a \ref DistMap. 
+    ///\param g is the digraph, to which we would like to define the \ref DistMap
+#ifdef DOXYGEN
+    static DistMap *createDistMap(const GR &g)
+#else
+    static DistMap *createDistMap(const GR &)
+#endif
+    {
+      return new DistMap();
+    }
+  };
+  
+  /// Default traits used by \ref DfsWizard
+
+  /// To make it easier to use Dfs algorithm
+  ///we have created a wizard class.
+  /// This \ref DfsWizard class needs default traits,
+  ///as well as the \ref Dfs class.
+  /// The \ref DfsWizardBase is a class to be the default traits of the
+  /// \ref DfsWizard class.
+  template<class GR>
+  class DfsWizardBase : public DfsWizardDefaultTraits<GR>
+  {
+
+    typedef DfsWizardDefaultTraits<GR> Base;
+  protected:
+    /// Type of the nodes in the digraph.
+    typedef typename Base::Digraph::Node Node;
+
+    /// Pointer to the underlying digraph.
+    void *_g;
+    ///Pointer to the map of reached nodes.
+    void *_reached;
+    ///Pointer to the map of processed nodes.
+    void *_processed;
+    ///Pointer to the map of predecessors arcs.
+    void *_pred;
+    ///Pointer to the map of distances.
+    void *_dist;
+    ///Pointer to the source node.
+    Node _source;
+    
+    public:
+    /// Constructor.
+    
+    /// This constructor does not require parameters, therefore it initiates
+    /// all of the attributes to default values (0, INVALID).
+    DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
+			   _dist(0), _source(INVALID) {}
+
+    /// Constructor.
+    
+    /// This constructor requires some parameters,
+    /// listed in the parameters list.
+    /// Others are initiated to 0.
+    /// \param g is the initial value of  \ref _g
+    /// \param s is the initial value of  \ref _source
+    DfsWizardBase(const GR &g, Node s=INVALID) :
+      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
+      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
+
+  };
+  
+  /// A class to make the usage of the Dfs algorithm easier
+
+  /// This class is created to make it easier to use the Dfs algorithm.
+  /// It uses the functions and features of the plain \ref Dfs,
+  /// but it is much simpler to use it.
+  ///
+  /// Simplicity means that the way to change the types defined
+  /// in the traits class is based on functions that returns the new class
+  /// and not on templatable built-in classes.
+  /// When using the plain \ref Dfs
+  /// the new class with the modified type comes from
+  /// the original class by using the ::
+  /// operator. In the case of \ref DfsWizard only
+  /// a function have to be called and it will
+  /// return the needed class.
+  ///
+  /// It does not have own \ref run method. When its \ref run method is called
+  /// it initiates a plain \ref Dfs object, and calls the \ref Dfs::run
+  /// method of it.
+  template<class TR>
+  class DfsWizard : public TR
+  {
+    typedef TR Base;
+
+    ///The type of the underlying digraph.
+    typedef typename TR::Digraph Digraph;
+    //\e
+    typedef typename Digraph::Node Node;
+    //\e
+    typedef typename Digraph::NodeIt NodeIt;
+    //\e
+    typedef typename Digraph::Arc Arc;
+    //\e
+    typedef typename Digraph::OutArcIt OutArcIt;
+    
+    ///\brief The type of the map that stores
+    ///the reached nodes
+    typedef typename TR::ReachedMap ReachedMap;
+    ///\brief The type of the map that stores
+    ///the processed nodes
+    typedef typename TR::ProcessedMap ProcessedMap;
+    ///\brief The type of the map that stores the last
+    ///arcs of the %DFS paths.
+    typedef typename TR::PredMap PredMap;
+    ///The type of the map that stores the distances of the nodes.
+    typedef typename TR::DistMap DistMap;
+
+  public:
+    /// Constructor.
+    DfsWizard() : TR() {}
+
+    /// Constructor that requires parameters.
+
+    /// Constructor that requires parameters.
+    /// These parameters will be the default values for the traits class.
+    DfsWizard(const Digraph &g, Node s=INVALID) :
+      TR(g,s) {}
+
+    ///Copy constructor
+    DfsWizard(const TR &b) : TR(b) {}
+
+    ~DfsWizard() {}
+
+    ///Runs Dfs algorithm from a given node.
+    
+    ///Runs Dfs algorithm from a given node.
+    ///The node can be given by the \ref source function.
+    void run()
+    {
+      if(Base::_source==INVALID) throw UninitializedParameter();
+      Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
+      if(Base::_reached) 
+        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
+      if(Base::_processed) 
+        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
+      if(Base::_pred) 
+        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
+      if(Base::_dist) 
+        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
+      alg.run(Base::_source);
+    }
+
+    ///Runs Dfs algorithm from the given node.
+
+    ///Runs Dfs algorithm from the given node.
+    ///\param s is the given source.
+    void run(Node s)
+    {
+      Base::_source=s;
+      run();
+    }
+
+    template<class T>
+    struct DefPredMapBase : public Base {
+      typedef T PredMap;
+      static PredMap *createPredMap(const Digraph &) { return 0; };
+      DefPredMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting PredMap type
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting PredMap type
+    ///
+    template<class T>
+    DfsWizard<DefPredMapBase<T> > predMap(const T &t) 
+    {
+      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return DfsWizard<DefPredMapBase<T> >(*this);
+    }
+    
+ 
+    template<class T>
+    struct DefReachedMapBase : public Base {
+      typedef T ReachedMap;
+      static ReachedMap *createReachedMap(const Digraph &) { return 0; };
+      DefReachedMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting ReachedMap
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting ReachedMap
+    ///
+    template<class T>
+    DfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
+    {
+      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return DfsWizard<DefReachedMapBase<T> >(*this);
+    }
+    
+
+    template<class T>
+    struct DefProcessedMapBase : public Base {
+      typedef T ProcessedMap;
+      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
+      DefProcessedMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting ProcessedMap
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting ProcessedMap
+    ///
+    template<class T>
+    DfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
+    {
+      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return DfsWizard<DefProcessedMapBase<T> >(*this);
+    }
+    
+    template<class T>
+    struct DefDistMapBase : public Base {
+      typedef T DistMap;
+      static DistMap *createDistMap(const Digraph &) { return 0; };
+      DefDistMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting DistMap type
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting DistMap type
+    ///
+    template<class T>
+    DfsWizard<DefDistMapBase<T> > distMap(const T &t) 
+    {
+      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return DfsWizard<DefDistMapBase<T> >(*this);
+    }
+    
+    /// Sets the source node, from which the Dfs algorithm runs.
+
+    /// Sets the source node, from which the Dfs algorithm runs.
+    /// \param s is the source node.
+    DfsWizard<TR> &source(Node s) 
+    {
+      Base::_source=s;
+      return *this;
+    }
+    
+  };
+  
+  ///Function type interface for Dfs algorithm.
+
+  ///\ingroup search
+  ///Function type interface for Dfs algorithm.
+  ///
+  ///This function also has several
+  ///\ref named-templ-func-param "named parameters",
+  ///they are declared as the members of class \ref DfsWizard.
+  ///The following
+  ///example shows how to use these parameters.
+  ///\code
+  ///  dfs(g,source).predMap(preds).run();
+  ///\endcode
+  ///\warning Don't forget to put the \ref DfsWizard::run() "run()"
+  ///to the end of the parameter list.
+  ///\sa DfsWizard
+  ///\sa Dfs
+  template<class GR>
+  DfsWizard<DfsWizardBase<GR> >
+  dfs(const GR &g,typename GR::Node s=INVALID)
+  {
+    return DfsWizard<DfsWizardBase<GR> >(g,s);
+  }
+
+#ifdef DOXYGEN
+  /// \brief Visitor class for dfs.
+  ///  
+  /// It gives a simple interface for a functional interface for dfs 
+  /// traversal. The traversal on a linear data structure. 
+  template <typename _Digraph>
+  struct DfsVisitor {
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+    typedef typename Digraph::Node Node;
+    /// \brief Called when the arc reach a node.
+    /// 
+    /// It is called when the dfs find an arc which target is not
+    /// reached yet.
+    void discover(const Arc& arc) {}
+    /// \brief Called when the node reached first time.
+    /// 
+    /// It is Called when the node reached first time.
+    void reach(const Node& node) {}
+    /// \brief Called when we step back on an arc.
+    /// 
+    /// It is called when the dfs should step back on the arc.
+    void backtrack(const Arc& arc) {}
+    /// \brief Called when we step back from the node.
+    /// 
+    /// It is called when we step back from the node.
+    void leave(const Node& node) {}
+    /// \brief Called when the arc examined but target of the arc 
+    /// already discovered.
+    /// 
+    /// It called when the arc examined but the target of the arc 
+    /// already discovered.
+    void examine(const Arc& arc) {}
+    /// \brief Called for the source node of the dfs.
+    /// 
+    /// It is called for the source node of the dfs.
+    void start(const Node& node) {}
+    /// \brief Called when we leave the source node of the dfs.
+    /// 
+    /// It is called when we leave the source node of the dfs.
+    void stop(const Node& node) {}
+
+  };
+#else
+  template <typename _Digraph>
+  struct DfsVisitor {
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+    typedef typename Digraph::Node Node;
+    void discover(const Arc&) {}
+    void reach(const Node&) {}
+    void backtrack(const Arc&) {}
+    void leave(const Node&) {}
+    void examine(const Arc&) {}
+    void start(const Node&) {}
+    void stop(const Node&) {}
+
+    template <typename _Visitor>
+    struct Constraints {
+      void constraints() {
+	Arc arc;
+	Node node;
+	visitor.discover(arc);
+	visitor.reach(node);
+	visitor.backtrack(arc);
+	visitor.leave(node);
+	visitor.examine(arc);
+	visitor.start(node);
+	visitor.stop(arc);
+      }
+      _Visitor& visitor;
+    };
+  };
+#endif
+
+  /// \brief Default traits class of DfsVisit class.
+  ///
+  /// Default traits class of DfsVisit class.
+  /// \param _Digraph Digraph type.
+  template<class _Digraph>
+  struct DfsVisitDefaultTraits {
+
+    /// \brief The digraph type the algorithm runs on. 
+    typedef _Digraph Digraph;
+
+    /// \brief The type of the map that indicates which nodes are reached.
+    /// 
+    /// The type of the map that indicates which nodes are reached.
+    /// It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    /// \todo named parameter to set this type, function to read and write.
+    typedef typename Digraph::template NodeMap<bool> ReachedMap;
+
+    /// \brief Instantiates a ReachedMap.
+    ///
+    /// This function instantiates a \ref ReachedMap. 
+    /// \param digraph is the digraph, to which
+    /// we would like to define the \ref ReachedMap.
+    static ReachedMap *createReachedMap(const Digraph &digraph) {
+      return new ReachedMap(digraph);
+    }
+
+  };
+  
+  /// %DFS Visit algorithm class.
+  
+  /// \ingroup search
+  /// This class provides an efficient implementation of the %DFS algorithm
+  /// with visitor interface.
+  ///
+  /// The %DfsVisit class provides an alternative interface to the Dfs
+  /// class. It works with callback mechanism, the DfsVisit object calls
+  /// on every dfs event the \c Visitor class member functions. 
+  ///
+  /// \param _Digraph The digraph type the algorithm runs on. The default value is
+  /// \ref ListDigraph. The value of _Digraph is not used directly by Dfs, it
+  /// is only passed to \ref DfsDefaultTraits.
+  /// \param _Visitor The Visitor object for the algorithm. The 
+  /// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty Visitor which
+  /// does not observe the Dfs events. If you want to observe the dfs
+  /// events you should implement your own Visitor class.
+  /// \param _Traits Traits class to set various data types used by the 
+  /// algorithm. The default traits class is
+  /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<_Digraph>".
+  /// See \ref DfsVisitDefaultTraits for the documentation of
+  /// a Dfs visit traits class.
+  ///
+  /// \author Jacint Szabo, Alpar Juttner and Balazs Dezso
+#ifdef DOXYGEN
+  template <typename _Digraph, typename _Visitor, typename _Traits>
+#else
+  template <typename _Digraph = ListDigraph,
+	    typename _Visitor = DfsVisitor<_Digraph>,
+	    typename _Traits = DfsDefaultTraits<_Digraph> >
+#endif
+  class DfsVisit {
+  public:
+    
+    /// \brief \ref Exception for uninitialized parameters.
+    ///
+    /// This error represents problems in the initialization
+    /// of the parameters of the algorithms.
+    class UninitializedParameter : public lemon::UninitializedParameter {
+    public:
+      virtual const char* what() const throw() 
+      {
+	return "lemon::DfsVisit::UninitializedParameter";
+      }
+    };
+
+    typedef _Traits Traits;
+
+    typedef typename Traits::Digraph Digraph;
+
+    typedef _Visitor Visitor;
+
+    ///The type of the map indicating which nodes are reached.
+    typedef typename Traits::ReachedMap ReachedMap;
+
+  private:
+
+    typedef typename Digraph::Node Node;
+    typedef typename Digraph::NodeIt NodeIt;
+    typedef typename Digraph::Arc Arc;
+    typedef typename Digraph::OutArcIt OutArcIt;
+
+    /// Pointer to the underlying digraph.
+    const Digraph *_digraph;
+    /// Pointer to the visitor object.
+    Visitor *_visitor;
+    ///Pointer to the map of reached status of the nodes.
+    ReachedMap *_reached;
+    ///Indicates if \ref _reached is locally allocated (\c true) or not.
+    bool local_reached;
+
+    std::vector<typename Digraph::Arc> _stack;
+    int _stack_head;
+
+    /// \brief Creates the maps if necessary.
+    ///
+    /// Creates the maps if necessary.
+    void create_maps() {
+      if(!_reached) {
+	local_reached = true;
+	_reached = Traits::createReachedMap(*_digraph);
+      }
+    }
+
+  protected:
+
+    DfsVisit() {}
+    
+  public:
+
+    typedef DfsVisit Create;
+
+    /// \name Named template parameters
+
+    ///@{
+    template <class T>
+    struct DefReachedMapTraits : public Traits {
+      typedef T ReachedMap;
+      static ReachedMap *createReachedMap(const Digraph &digraph) {
+	throw UninitializedParameter();
+      }
+    };
+    /// \brief \ref named-templ-param "Named parameter" for setting 
+    /// ReachedMap type
+    ///
+    /// \ref named-templ-param "Named parameter" for setting ReachedMap type
+    template <class T>
+    struct DefReachedMap : public DfsVisit< Digraph, Visitor,
+					    DefReachedMapTraits<T> > {
+      typedef DfsVisit< Digraph, Visitor, DefReachedMapTraits<T> > Create;
+    };
+    ///@}
+
+  public:      
+    
+    /// \brief Constructor.
+    ///
+    /// Constructor.
+    ///
+    /// \param digraph the digraph the algorithm will run on.
+    /// \param visitor The visitor of the algorithm.
+    ///
+    DfsVisit(const Digraph& digraph, Visitor& visitor) 
+      : _digraph(&digraph), _visitor(&visitor),
+	_reached(0), local_reached(false) {}
+    
+    /// \brief Destructor.
+    ///
+    /// Destructor.
+    ~DfsVisit() {
+      if(local_reached) delete _reached;
+    }
+
+    /// \brief Sets the map indicating if a node is reached.
+    ///
+    /// Sets the map indicating if a node is reached.
+    /// If you don't use this function before calling \ref run(),
+    /// it will allocate one. The destuctor deallocates this
+    /// automatically allocated map, of course.
+    /// \return <tt> (*this) </tt>
+    DfsVisit &reachedMap(ReachedMap &m) {
+      if(local_reached) {
+	delete _reached;
+	local_reached=false;
+      }
+      _reached = &m;
+      return *this;
+    }
+
+  public:
+    /// \name Execution control
+    /// The simplest way to execute the algorithm is to use
+    /// one of the member functions called \c run(...).
+    /// \n
+    /// If you need more control on the execution,
+    /// first you must call \ref init(), then you can adda source node
+    /// with \ref addSource().
+    /// Finally \ref start() will perform the actual path
+    /// computation.
+
+    /// @{
+    /// \brief Initializes the internal data structures.
+    ///
+    /// Initializes the internal data structures.
+    ///
+    void init() {
+      create_maps();
+      _stack.resize(countNodes(*_digraph));
+      _stack_head = -1;
+      for (NodeIt u(*_digraph) ; u != INVALID ; ++u) {
+	_reached->set(u, false);
+      }
+    }
+    
+    /// \brief Adds a new source node.
+    ///
+    /// Adds a new source node to the set of nodes to be processed.
+    void addSource(Node s) {
+      if(!(*_reached)[s]) {
+	  _reached->set(s,true);
+	  _visitor->start(s);
+	  _visitor->reach(s);
+	  Arc e; 
+	  _digraph->firstOut(e, s);
+	  if (e != INVALID) {
+	    _stack[++_stack_head] = e;
+	  } else {
+	    _visitor->leave(s);
+	  }
+	}
+    }
+    
+    /// \brief Processes the next arc.
+    ///
+    /// Processes the next arc.
+    ///
+    /// \return The processed arc.
+    ///
+    /// \pre The stack must not be empty!
+    Arc processNextArc() { 
+      Arc e = _stack[_stack_head];
+      Node m = _digraph->target(e);
+      if(!(*_reached)[m]) {
+	_visitor->discover(e);
+	_visitor->reach(m);
+	_reached->set(m, true);
+	_digraph->firstOut(_stack[++_stack_head], m);
+      } else {
+	_visitor->examine(e);
+	m = _digraph->source(e);
+	_digraph->nextOut(_stack[_stack_head]);
+      }
+      while (_stack_head>=0 && _stack[_stack_head] == INVALID) {
+	_visitor->leave(m);
+	--_stack_head;
+	if (_stack_head >= 0) {
+	  _visitor->backtrack(_stack[_stack_head]);
+	  m = _digraph->source(_stack[_stack_head]);
+	  _digraph->nextOut(_stack[_stack_head]);
+	} else {
+	  _visitor->stop(m);	  
+	}
+      }
+      return e;
+    }
+
+    /// \brief Next arc to be processed.
+    ///
+    /// Next arc to be processed.
+    ///
+    /// \return The next arc to be processed or INVALID if the stack is
+    /// empty.
+    Arc nextArc() { 
+      return _stack_head >= 0 ? _stack[_stack_head] : INVALID;
+    }
+
+    /// \brief Returns \c false if there are nodes
+    /// to be processed in the queue
+    ///
+    /// Returns \c false if there are nodes
+    /// to be processed in the queue
+    bool emptyQueue() { return _stack_head < 0; }
+
+    /// \brief Returns the number of the nodes to be processed.
+    ///
+    /// Returns the number of the nodes to be processed in the queue.
+    int queueSize() { return _stack_head + 1; }
+    
+    /// \brief Executes the algorithm.
+    ///
+    /// Executes the algorithm.
+    ///
+    /// \pre init() must be called and at least one node should be added
+    /// with addSource() before using this function.
+    void start() {
+      while ( !emptyQueue() ) processNextArc();
+    }
+    
+    /// \brief Executes the algorithm until \c dest is reached.
+    ///
+    /// Executes the algorithm until \c dest is reached.
+    ///
+    /// \pre init() must be called and at least one node should be added
+    /// with addSource() before using this function.
+    void start(Node dest) {
+      while ( !emptyQueue() && _digraph->target(_stack[_stack_head]) != dest ) 
+	processNextArc();
+    }
+    
+    /// \brief Executes the algorithm until a condition is met.
+    ///
+    /// Executes the algorithm until a condition is met.
+    ///
+    /// \pre init() must be called and at least one node should be added
+    /// with addSource() before using this function.
+    ///
+    /// \param em must be a bool (or convertible) arc map. The algorithm
+    /// will stop when it reaches an arc \c e with <tt>em[e]</tt> true.
+    ///
+    ///\return The reached arc \c e with <tt>em[e]</tt> true or
+    ///\c INVALID if no such arc was found.
+    ///
+    /// \warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an arc map,
+    /// not a node map.
+    template <typename EM>
+    Arc start(const EM &em) {
+      while ( !emptyQueue() && !em[_stack[_stack_head]] )
+        processNextArc();
+      return emptyQueue() ? INVALID : _stack[_stack_head];
+    }
+
+    /// \brief Runs %DFSVisit algorithm from node \c s.
+    ///
+    /// This method runs the %DFS algorithm from a root node \c s.
+    /// \note d.run(s) is just a shortcut of the following code.
+    ///\code
+    ///   d.init();
+    ///   d.addSource(s);
+    ///   d.start();
+    ///\endcode
+    void run(Node s) {
+      init();
+      addSource(s);
+      start();
+    }
+
+    /// \brief Runs %DFSVisit algorithm to visit all nodes in the digraph.
+    
+    /// This method runs the %DFS algorithm in order to
+    /// compute the %DFS path to each node. The algorithm computes
+    /// - The %DFS tree.
+    /// - The distance of each node from the root in the %DFS tree.
+    ///
+    ///\note d.run() is just a shortcut of the following code.
+    ///\code
+    ///  d.init();
+    ///  for (NodeIt it(digraph); it != INVALID; ++it) {
+    ///    if (!d.reached(it)) {
+    ///      d.addSource(it);
+    ///      d.start();
+    ///    }
+    ///  }
+    ///\endcode
+    void run() {
+      init();
+      for (NodeIt it(*_digraph); it != INVALID; ++it) {
+        if (!reached(it)) {
+          addSource(it);
+          start();
+        }
+      }
+    }
+    ///@}
+
+    /// \name Query Functions
+    /// The result of the %DFS algorithm can be obtained using these
+    /// functions.\n
+    /// Before the use of these functions,
+    /// either run() or start() must be called.
+    ///@{
+    /// \brief Checks if a node is reachable from the root.
+    ///
+    /// Returns \c true if \c v is reachable from the root(s).
+    /// \warning The source nodes are inditated as unreachable.
+    /// \pre Either \ref run() or \ref start()
+    /// must be called before using this function.
+    ///
+    bool reached(Node v) { return (*_reached)[v]; }
+    ///@}
+  };
+
+
+} //END OF NAMESPACE LEMON
+
+#endif
+
Index: lemon/dijkstra.h
===================================================================
--- lemon/dijkstra.h	(revision 100)
+++ lemon/dijkstra.h	(revision 100)
@@ -0,0 +1,1209 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_DIJKSTRA_H
+#define LEMON_DIJKSTRA_H
+
+///\ingroup shortest_path
+///\file
+///\brief Dijkstra algorithm.
+///
+
+#include <lemon/list_digraph.h>
+#include <lemon/bin_heap.h>
+#include <lemon/bits/path_dump.h>
+#include <lemon/bits/invalid.h>
+#include <lemon/error.h>
+#include <lemon/maps.h>
+
+
+namespace lemon {
+
+  /// \brief Default OperationTraits for the Dijkstra algorithm class.
+  ///  
+  /// It defines all computational operations and constants which are
+  /// used in the Dijkstra algorithm.
+  template <typename Value>
+  struct DijkstraDefaultOperationTraits {
+    /// \brief Gives back the zero value of the type.
+    static Value zero() {
+      return static_cast<Value>(0);
+    }
+    /// \brief Gives back the sum of the given two elements.
+    static Value plus(const Value& left, const Value& right) {
+      return left + right;
+    }
+    /// \brief Gives back true only if the first value less than the second.
+    static bool less(const Value& left, const Value& right) {
+      return left < right;
+    }
+  };
+
+  /// \brief Widest path OperationTraits for the Dijkstra algorithm class.
+  ///  
+  /// It defines all computational operations and constants which are
+  /// used in the Dijkstra algorithm for widest path computation.
+  template <typename Value>
+  struct DijkstraWidestPathOperationTraits {
+    /// \brief Gives back the maximum value of the type.
+    static Value zero() {
+      return std::numeric_limits<Value>::max();
+    }
+    /// \brief Gives back the minimum of the given two elements.
+    static Value plus(const Value& left, const Value& right) {
+      return std::min(left, right);
+    }
+    /// \brief Gives back true only if the first value less than the second.
+    static bool less(const Value& left, const Value& right) {
+      return left < right;
+    }
+  };
+  
+  ///Default traits class of Dijkstra class.
+
+  ///Default traits class of Dijkstra class.
+  ///\param GR Digraph type.
+  ///\param LM Type of length map.
+  template<class GR, class LM>
+  struct DijkstraDefaultTraits
+  {
+    ///The digraph type the algorithm runs on. 
+    typedef GR Digraph;
+    ///The type of the map that stores the arc lengths.
+
+    ///The type of the map that stores the arc lengths.
+    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
+    typedef LM LengthMap;
+    //The type of the length of the arcs.
+    typedef typename LM::Value Value;
+    /// Operation traits for Dijkstra algorithm.
+
+    /// It defines the used operation by the algorithm.
+    /// \see DijkstraDefaultOperationTraits
+    typedef DijkstraDefaultOperationTraits<Value> OperationTraits;
+    /// The cross reference type used by heap.
+
+
+    /// The cross reference type used by heap.
+    /// Usually it is \c Digraph::NodeMap<int>.
+    typedef typename Digraph::template NodeMap<int> HeapCrossRef;
+    ///Instantiates a HeapCrossRef.
+
+    ///This function instantiates a \c HeapCrossRef. 
+    /// \param G is the digraph, to which we would like to define the 
+    /// HeapCrossRef.
+    static HeapCrossRef *createHeapCrossRef(const GR &G) 
+    {
+      return new HeapCrossRef(G);
+    }
+    
+    ///The heap type used by Dijkstra algorithm.
+
+    ///The heap type used by Dijkstra algorithm.
+    ///
+    ///\sa BinHeap
+    ///\sa Dijkstra
+    typedef BinHeap<typename LM::Value, HeapCrossRef, std::less<Value> > Heap;
+
+    static Heap *createHeap(HeapCrossRef& R) 
+    {
+      return new Heap(R);
+    }
+
+    ///\brief The type of the map that stores the last
+    ///arcs of the shortest paths.
+    /// 
+    ///The type of the map that stores the last
+    ///arcs of the shortest paths.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
+    ///Instantiates a PredMap.
+ 
+    ///This function instantiates a \c PredMap. 
+    ///\param G is the digraph, to which we would like to define the PredMap.
+    ///\todo The digraph alone may be insufficient for the initialization
+    static PredMap *createPredMap(const GR &G) 
+    {
+      return new PredMap(G);
+    }
+
+    ///The type of the map that stores whether a nodes is processed.
+ 
+    ///The type of the map that stores whether a nodes is processed.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///By default it is a NullMap.
+    ///\todo If it is set to a real map,
+    ///Dijkstra::processed() should read this.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
+    ///Instantiates a ProcessedMap.
+ 
+    ///This function instantiates a \c ProcessedMap. 
+    ///\param g is the digraph, to which
+    ///we would like to define the \c ProcessedMap
+#ifdef DOXYGEN
+    static ProcessedMap *createProcessedMap(const GR &g)
+#else
+    static ProcessedMap *createProcessedMap(const GR &)
+#endif
+    {
+      return new ProcessedMap();
+    }
+    ///The type of the map that stores the dists of the nodes.
+ 
+    ///The type of the map that stores the dists of the nodes.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef typename Digraph::template NodeMap<typename LM::Value> DistMap;
+    ///Instantiates a DistMap.
+ 
+    ///This function instantiates a \ref DistMap. 
+    ///\param G is the digraph, to which we would like to define the \ref DistMap
+    static DistMap *createDistMap(const GR &G)
+    {
+      return new DistMap(G);
+    }
+  };
+  
+  ///%Dijkstra algorithm class.
+  
+  /// \ingroup shortest_path
+  ///This class provides an efficient implementation of %Dijkstra algorithm.
+  ///The arc lengths are passed to the algorithm using a
+  ///\ref concepts::ReadMap "ReadMap",
+  ///so it is easy to change it to any kind of length.
+  ///
+  ///The type of the length is determined by the
+  ///\ref concepts::ReadMap::Value "Value" of the length map.
+  ///
+  ///It is also possible to change the underlying priority heap.
+  ///
+  ///\param GR The digraph type the algorithm runs on. The default value
+  ///is \ref ListDigraph. The value of GR is not used directly by
+  ///Dijkstra, it is only passed to \ref DijkstraDefaultTraits.
+  ///\param LM This read-only ArcMap determines the lengths of the
+  ///arcs. It is read once for each arc, so the map may involve in
+  ///relatively time consuming process to compute the arc length if
+  ///it is necessary. The default map type is \ref
+  ///concepts::Digraph::ArcMap "Digraph::ArcMap<int>".  The value
+  ///of LM is not used directly by Dijkstra, it is only passed to \ref
+  ///DijkstraDefaultTraits.  \param TR Traits class to set
+  ///various data types used by the algorithm.  The default traits
+  ///class is \ref DijkstraDefaultTraits
+  ///"DijkstraDefaultTraits<GR,LM>".  See \ref
+  ///DijkstraDefaultTraits for the documentation of a Dijkstra traits
+  ///class.
+  ///
+  ///\author Jacint Szabo and Alpar Juttner
+
+#ifdef DOXYGEN
+  template <typename GR, typename LM, typename TR>
+#else
+  template <typename GR=ListDigraph,
+	    typename LM=typename GR::template ArcMap<int>,
+	    typename TR=DijkstraDefaultTraits<GR,LM> >
+#endif
+  class Dijkstra {
+  public:
+    /**
+     * \brief \ref Exception for uninitialized parameters.
+     *
+     * This error represents problems in the initialization
+     * of the parameters of the algorithms.
+     */
+    class UninitializedParameter : public lemon::UninitializedParameter {
+    public:
+      virtual const char* what() const throw() {
+	return "lemon::Dijkstra::UninitializedParameter";
+      }
+    };
+
+    typedef TR Traits;
+    ///The type of the underlying digraph.
+    typedef typename TR::Digraph Digraph;
+    ///\e
+    typedef typename Digraph::Node Node;
+    ///\e
+    typedef typename Digraph::NodeIt NodeIt;
+    ///\e
+    typedef typename Digraph::Arc Arc;
+    ///\e
+    typedef typename Digraph::OutArcIt OutArcIt;
+    
+    ///The type of the length of the arcs.
+    typedef typename TR::LengthMap::Value Value;
+    ///The type of the map that stores the arc lengths.
+    typedef typename TR::LengthMap LengthMap;
+    ///\brief The type of the map that stores the last
+    ///arcs of the shortest paths.
+    typedef typename TR::PredMap PredMap;
+    ///The type of the map indicating if a node is processed.
+    typedef typename TR::ProcessedMap ProcessedMap;
+    ///The type of the map that stores the dists of the nodes.
+    typedef typename TR::DistMap DistMap;
+    ///The cross reference type used for the current heap.
+    typedef typename TR::HeapCrossRef HeapCrossRef;
+    ///The heap type used by the dijkstra algorithm.
+    typedef typename TR::Heap Heap;
+    ///The operation traits.
+    typedef typename TR::OperationTraits OperationTraits;
+  private:
+    /// Pointer to the underlying digraph.
+    const Digraph *G;
+    /// Pointer to the length map
+    const LengthMap *length;
+    ///Pointer to the map of predecessors arcs.
+    PredMap *_pred;
+    ///Indicates if \ref _pred is locally allocated (\c true) or not.
+    bool local_pred;
+    ///Pointer to the map of distances.
+    DistMap *_dist;
+    ///Indicates if \ref _dist is locally allocated (\c true) or not.
+    bool local_dist;
+    ///Pointer to the map of processed status of the nodes.
+    ProcessedMap *_processed;
+    ///Indicates if \ref _processed is locally allocated (\c true) or not.
+    bool local_processed;
+    ///Pointer to the heap cross references.
+    HeapCrossRef *_heap_cross_ref;
+    ///Indicates if \ref _heap_cross_ref is locally allocated (\c true) or not.
+    bool local_heap_cross_ref;
+    ///Pointer to the heap.
+    Heap *_heap;
+    ///Indicates if \ref _heap is locally allocated (\c true) or not.
+    bool local_heap;
+
+    ///Creates the maps if necessary.
+    
+    ///\todo Better memory allocation (instead of new).
+    void create_maps() 
+    {
+      if(!_pred) {
+	local_pred = true;
+	_pred = Traits::createPredMap(*G);
+      }
+      if(!_dist) {
+	local_dist = true;
+	_dist = Traits::createDistMap(*G);
+      }
+      if(!_processed) {
+	local_processed = true;
+	_processed = Traits::createProcessedMap(*G);
+      }
+      if (!_heap_cross_ref) {
+	local_heap_cross_ref = true;
+	_heap_cross_ref = Traits::createHeapCrossRef(*G);
+      }
+      if (!_heap) {
+	local_heap = true;
+	_heap = Traits::createHeap(*_heap_cross_ref);
+      }
+    }
+    
+  public :
+
+    typedef Dijkstra Create;
+ 
+    ///\name Named template parameters
+
+    ///@{
+
+    template <class T>
+    struct DefPredMapTraits : public Traits {
+      typedef T PredMap;
+      static PredMap *createPredMap(const Digraph &)
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\ref named-templ-param "Named parameter" for setting PredMap type
+
+    ///\ref named-templ-param "Named parameter" for setting PredMap type
+    ///
+    template <class T>
+    struct DefPredMap 
+      : public Dijkstra< Digraph,	LengthMap, DefPredMapTraits<T> > {
+      typedef Dijkstra< Digraph,	LengthMap, DefPredMapTraits<T> > Create;
+    };
+    
+    template <class T>
+    struct DefDistMapTraits : public Traits {
+      typedef T DistMap;
+      static DistMap *createDistMap(const Digraph &)
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\ref named-templ-param "Named parameter" for setting DistMap type
+
+    ///\ref named-templ-param "Named parameter" for setting DistMap type
+    ///
+    template <class T>
+    struct DefDistMap 
+      : public Dijkstra< Digraph, LengthMap, DefDistMapTraits<T> > { 
+      typedef Dijkstra< Digraph, LengthMap, DefDistMapTraits<T> > Create;
+    };
+    
+    template <class T>
+    struct DefProcessedMapTraits : public Traits {
+      typedef T ProcessedMap;
+      static ProcessedMap *createProcessedMap(const Digraph &G) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
+
+    ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
+    ///
+    template <class T>
+    struct DefProcessedMap 
+      : public Dijkstra< Digraph,	LengthMap, DefProcessedMapTraits<T> > { 
+      typedef Dijkstra< Digraph,	LengthMap, DefProcessedMapTraits<T> > Create;
+    };
+    
+    struct DefDigraphProcessedMapTraits : public Traits {
+      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
+      static ProcessedMap *createProcessedMap(const Digraph &G) 
+      {
+	return new ProcessedMap(G);
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter"
+    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
+    ///
+    ///\ref named-templ-param "Named parameter"
+    ///for setting the ProcessedMap type to be Digraph::NodeMap<bool>.
+    ///If you don't set it explicitely, it will be automatically allocated.
+    template <class T>
+    struct DefProcessedMapToBeDefaultMap 
+      : public Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> {
+      typedef Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> Create;
+    };
+
+    template <class H, class CR>
+    struct DefHeapTraits : public Traits {
+      typedef CR HeapCrossRef;
+      typedef H Heap;
+      static HeapCrossRef *createHeapCrossRef(const Digraph &) {
+	throw UninitializedParameter();
+      }
+      static Heap *createHeap(HeapCrossRef &) 
+      {
+	throw UninitializedParameter();
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///heap and cross reference type
+    ///
+    ///\ref named-templ-param "Named parameter" for setting heap and cross 
+    ///reference type
+    ///
+    template <class H, class CR = typename Digraph::template NodeMap<int> >
+    struct DefHeap
+      : public Dijkstra< Digraph,	LengthMap, DefHeapTraits<H, CR> > { 
+      typedef Dijkstra< Digraph,	LengthMap, DefHeapTraits<H, CR> > Create;
+    };
+
+    template <class H, class CR>
+    struct DefStandardHeapTraits : public Traits {
+      typedef CR HeapCrossRef;
+      typedef H Heap;
+      static HeapCrossRef *createHeapCrossRef(const Digraph &G) {
+	return new HeapCrossRef(G);
+      }
+      static Heap *createHeap(HeapCrossRef &R) 
+      {
+	return new Heap(R);
+      }
+    };
+    ///\brief \ref named-templ-param "Named parameter" for setting
+    ///heap and cross reference type with automatic allocation
+    ///
+    ///\ref named-templ-param "Named parameter" for setting heap and cross 
+    ///reference type. It can allocate the heap and the cross reference 
+    ///object if the cross reference's constructor waits for the digraph as 
+    ///parameter and the heap's constructor waits for the cross reference.
+    template <class H, class CR = typename Digraph::template NodeMap<int> >
+    struct DefStandardHeap
+      : public Dijkstra< Digraph,	LengthMap, DefStandardHeapTraits<H, CR> > { 
+      typedef Dijkstra< Digraph,	LengthMap, DefStandardHeapTraits<H, CR> > 
+      Create;
+    };
+
+    template <class T>
+    struct DefOperationTraitsTraits : public Traits {
+      typedef T OperationTraits;
+    };
+    
+    /// \brief \ref named-templ-param "Named parameter" for setting 
+    /// OperationTraits type
+    ///
+    /// \ref named-templ-param "Named parameter" for setting OperationTraits
+    /// type
+    template <class T>
+    struct DefOperationTraits
+      : public Dijkstra<Digraph, LengthMap, DefOperationTraitsTraits<T> > {
+      typedef Dijkstra<Digraph, LengthMap, DefOperationTraitsTraits<T> >
+      Create;
+    };
+    
+    ///@}
+
+
+  protected:
+
+    Dijkstra() {}
+
+  public:      
+    
+    ///Constructor.
+    
+    ///\param _G the digraph the algorithm will run on.
+    ///\param _length the length map used by the algorithm.
+    Dijkstra(const Digraph& _G, const LengthMap& _length) :
+      G(&_G), length(&_length),
+      _pred(NULL), local_pred(false),
+      _dist(NULL), local_dist(false),
+      _processed(NULL), local_processed(false),
+      _heap_cross_ref(NULL), local_heap_cross_ref(false),
+      _heap(NULL), local_heap(false)
+    { }
+    
+    ///Destructor.
+    ~Dijkstra() 
+    {
+      if(local_pred) delete _pred;
+      if(local_dist) delete _dist;
+      if(local_processed) delete _processed;
+      if(local_heap_cross_ref) delete _heap_cross_ref;
+      if(local_heap) delete _heap;
+    }
+
+    ///Sets the length map.
+
+    ///Sets the length map.
+    ///\return <tt> (*this) </tt>
+    Dijkstra &lengthMap(const LengthMap &m) 
+    {
+      length = &m;
+      return *this;
+    }
+
+    ///Sets the map storing the predecessor arcs.
+
+    ///Sets the map storing the predecessor arcs.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destuctor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Dijkstra &predMap(PredMap &m) 
+    {
+      if(local_pred) {
+	delete _pred;
+	local_pred=false;
+      }
+      _pred = &m;
+      return *this;
+    }
+
+    ///Sets the map storing the distances calculated by the algorithm.
+
+    ///Sets the map storing the distances calculated by the algorithm.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destuctor deallocates this
+    ///automatically allocated map, of course.
+    ///\return <tt> (*this) </tt>
+    Dijkstra &distMap(DistMap &m) 
+    {
+      if(local_dist) {
+	delete _dist;
+	local_dist=false;
+      }
+      _dist = &m;
+      return *this;
+    }
+
+    ///Sets the heap and the cross reference used by algorithm.
+
+    ///Sets the heap and the cross reference used by algorithm.
+    ///If you don't use this function before calling \ref run(),
+    ///it will allocate one. The destuctor deallocates this
+    ///automatically allocated heap and cross reference, of course.
+    ///\return <tt> (*this) </tt>
+    Dijkstra &heap(Heap& hp, HeapCrossRef &cr)
+    {
+      if(local_heap_cross_ref) {
+	delete _heap_cross_ref;
+	local_heap_cross_ref=false;
+      }
+      _heap_cross_ref = &cr;
+      if(local_heap) {
+	delete _heap;
+	local_heap=false;
+      }
+      _heap = &hp;
+      return *this;
+    }
+
+  private:
+    void finalizeNodeData(Node v,Value dst)
+    {
+      _processed->set(v,true);
+      _dist->set(v, dst);
+    }
+
+  public:
+
+    typedef PredMapPath<Digraph, PredMap> Path;
+
+    ///\name Execution control
+    ///The simplest way to execute the algorithm is to use
+    ///one of the member functions called \c run(...).
+    ///\n
+    ///If you need more control on the execution,
+    ///first you must call \ref init(), then you can add several source nodes
+    ///with \ref addSource().
+    ///Finally \ref start() will perform the actual path
+    ///computation.
+
+    ///@{
+
+    ///Initializes the internal data structures.
+
+    ///Initializes the internal data structures.
+    ///
+    void init()
+    {
+      create_maps();
+      _heap->clear();
+      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
+	_pred->set(u,INVALID);
+	_processed->set(u,false);
+	_heap_cross_ref->set(u,Heap::PRE_HEAP);
+      }
+    }
+    
+    ///Adds a new source node.
+
+    ///Adds a new source node to the priority heap.
+    ///
+    ///The optional second parameter is the initial distance of the node.
+    ///
+    ///It checks if the node has already been added to the heap and
+    ///it is pushed to the heap only if either it was not in the heap
+    ///or the shortest path found till then is shorter than \c dst.
+    void addSource(Node s,Value dst=OperationTraits::zero())
+    {
+      if(_heap->state(s) != Heap::IN_HEAP) {
+	_heap->push(s,dst);
+      } else if(OperationTraits::less((*_heap)[s], dst)) {
+	_heap->set(s,dst);
+	_pred->set(s,INVALID);
+      }
+    }
+    
+    ///Processes the next node in the priority heap
+
+    ///Processes the next node in the priority heap.
+    ///
+    ///\return The processed node.
+    ///
+    ///\warning The priority heap must not be empty!
+    Node processNextNode()
+    {
+      Node v=_heap->top(); 
+      Value oldvalue=_heap->prio();
+      _heap->pop();
+      finalizeNodeData(v,oldvalue);
+      
+      for(OutArcIt e(*G,v); e!=INVALID; ++e) {
+	Node w=G->target(e); 
+	switch(_heap->state(w)) {
+	case Heap::PRE_HEAP:
+	  _heap->push(w,OperationTraits::plus(oldvalue, (*length)[e])); 
+	  _pred->set(w,e);
+	  break;
+	case Heap::IN_HEAP:
+	  {
+	    Value newvalue = OperationTraits::plus(oldvalue, (*length)[e]);
+	    if ( OperationTraits::less(newvalue, (*_heap)[w]) ) {
+	      _heap->decrease(w, newvalue); 
+	      _pred->set(w,e);
+	    }
+	  }
+	  break;
+	case Heap::POST_HEAP:
+	  break;
+	}
+      }
+      return v;
+    }
+
+    ///Next node to be processed.
+    
+    ///Next node to be processed.
+    ///
+    ///\return The next node to be processed or INVALID if the priority heap
+    /// is empty.
+    Node nextNode()
+    { 
+      return !_heap->empty()?_heap->top():INVALID;
+    }
+ 
+    ///\brief Returns \c false if there are nodes
+    ///to be processed in the priority heap
+    ///
+    ///Returns \c false if there are nodes
+    ///to be processed in the priority heap
+    bool emptyQueue() { return _heap->empty(); }
+    ///Returns the number of the nodes to be processed in the priority heap
+
+    ///Returns the number of the nodes to be processed in the priority heap
+    ///
+    int queueSize() { return _heap->size(); }
+    
+    ///Executes the algorithm.
+
+    ///Executes the algorithm.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///This method runs the %Dijkstra algorithm from the root node(s)
+    ///in order to
+    ///compute the
+    ///shortest path to each node. The algorithm computes
+    ///- The shortest path tree.
+    ///- The distance of each node from the root(s).
+    ///
+    void start()
+    {
+      while ( !_heap->empty() ) processNextNode();
+    }
+    
+    ///Executes the algorithm until \c dest is reached.
+
+    ///Executes the algorithm until \c dest is reached.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///This method runs the %Dijkstra algorithm from the root node(s)
+    ///in order to
+    ///compute the
+    ///shortest path to \c dest. The algorithm computes
+    ///- The shortest path to \c  dest.
+    ///- The distance of \c dest from the root(s).
+    ///
+    void start(Node dest)
+    {
+      while ( !_heap->empty() && _heap->top()!=dest ) processNextNode();
+      if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio());
+    }
+    
+    ///Executes the algorithm until a condition is met.
+
+    ///Executes the algorithm until a condition is met.
+    ///
+    ///\pre init() must be called and at least one node should be added
+    ///with addSource() before using this function.
+    ///
+    ///\param nm must be a bool (or convertible) node map. The algorithm
+    ///will stop when it reaches a node \c v with <tt>nm[v]</tt> true.
+    ///
+    ///\return The reached node \c v with <tt>nm[v]</tt> true or
+    ///\c INVALID if no such node was found.
+    template<class NodeBoolMap>
+    Node start(const NodeBoolMap &nm)
+    {
+      while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode();
+      if ( _heap->empty() ) return INVALID;
+      finalizeNodeData(_heap->top(),_heap->prio());
+      return _heap->top();
+    }
+    
+    ///Runs %Dijkstra algorithm from node \c s.
+    
+    ///This method runs the %Dijkstra algorithm from a root node \c s
+    ///in order to
+    ///compute the
+    ///shortest path to each node. The algorithm computes
+    ///- The shortest path tree.
+    ///- The distance of each node from the root.
+    ///
+    ///\note d.run(s) is just a shortcut of the following code.
+    ///\code
+    ///  d.init();
+    ///  d.addSource(s);
+    ///  d.start();
+    ///\endcode
+    void run(Node s) {
+      init();
+      addSource(s);
+      start();
+    }
+    
+    ///Finds the shortest path between \c s and \c t.
+    
+    ///Finds the shortest path between \c s and \c t.
+    ///
+    ///\return The length of the shortest s---t path if there exists one,
+    ///0 otherwise.
+    ///\note Apart from the return value, d.run(s) is
+    ///just a shortcut of the following code.
+    ///\code
+    ///  d.init();
+    ///  d.addSource(s);
+    ///  d.start(t);
+    ///\endcode
+    Value run(Node s,Node t) {
+      init();
+      addSource(s);
+      start(t);
+      return (*_pred)[t]==INVALID?OperationTraits::zero():(*_dist)[t];
+    }
+    
+    ///@}
+
+    ///\name Query Functions
+    ///The result of the %Dijkstra algorithm can be obtained using these
+    ///functions.\n
+    ///Before the use of these functions,
+    ///either run() or start() must be called.
+    
+    ///@{
+
+    ///Gives back the shortest path.
+    
+    ///Gives back the shortest path.
+    ///\pre The \c t should be reachable from the source.
+    Path path(Node t) 
+    {
+      return Path(*G, *_pred, t);
+    }
+
+    ///The distance of a node from the root.
+
+    ///Returns the distance of a node from the root.
+    ///\pre \ref run() must be called before using this function.
+    ///\warning If node \c v in unreachable from the root the return value
+    ///of this funcion is undefined.
+    Value dist(Node v) const { return (*_dist)[v]; }
+
+    ///The current distance of a node from the root.
+
+    ///Returns the current distance of a node from the root.
+    ///It may be decreased in the following processes.
+    ///\pre \c node should be reached but not processed
+    Value currentDist(Node v) const { return (*_heap)[v]; }
+
+    ///Returns the 'previous arc' of the shortest path tree.
+
+    ///For a node \c v it returns the 'previous arc' of the shortest path tree,
+    ///i.e. it returns the last arc of a shortest path from the root to \c
+    ///v. It is \ref INVALID
+    ///if \c v is unreachable from the root or if \c v=s. The
+    ///shortest path tree used here is equal to the shortest path tree used in
+    ///\ref predNode().  \pre \ref run() must be called before using
+    ///this function.
+    Arc predArc(Node v) const { return (*_pred)[v]; }
+
+    ///Returns the 'previous node' of the shortest path tree.
+
+    ///For a node \c v it returns the 'previous node' of the shortest path tree,
+    ///i.e. it returns the last but one node from a shortest path from the
+    ///root to \c /v. It is INVALID if \c v is unreachable from the root or if
+    ///\c v=s. The shortest path tree used here is equal to the shortest path
+    ///tree used in \ref predArc().  \pre \ref run() must be called before
+    ///using this function.
+    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
+				  G->source((*_pred)[v]); }
+    
+    ///Returns a reference to the NodeMap of distances.
+
+    ///Returns a reference to the NodeMap of distances. \pre \ref run() must
+    ///be called before using this function.
+    const DistMap &distMap() const { return *_dist;}
+ 
+    ///Returns a reference to the shortest path tree map.
+
+    ///Returns a reference to the NodeMap of the arcs of the
+    ///shortest path tree.
+    ///\pre \ref run() must be called before using this function.
+    const PredMap &predMap() const { return *_pred;}
+ 
+    ///Checks if a node is reachable from the root.
+
+    ///Returns \c true if \c v is reachable from the root.
+    ///\warning The source nodes are inditated as unreached.
+    ///\pre \ref run() must be called before using this function.
+    ///
+    bool reached(Node v) { return (*_heap_cross_ref)[v] != Heap::PRE_HEAP; }
+
+    ///Checks if a node is processed.
+
+    ///Returns \c true if \c v is processed, i.e. the shortest
+    ///path to \c v has already found.
+    ///\pre \ref run() must be called before using this function.
+    ///
+    bool processed(Node v) { return (*_heap_cross_ref)[v] == Heap::POST_HEAP; }
+    
+    ///@}
+  };
+
+
+
+
+ 
+  ///Default traits class of Dijkstra function.
+
+  ///Default traits class of Dijkstra function.
+  ///\param GR Digraph type.
+  ///\param LM Type of length map.
+  template<class GR, class LM>
+  struct DijkstraWizardDefaultTraits
+  {
+    ///The digraph type the algorithm runs on. 
+    typedef GR Digraph;
+    ///The type of the map that stores the arc lengths.
+
+    ///The type of the map that stores the arc lengths.
+    ///It must meet the \ref concepts::ReadMap "ReadMap" concept.
+    typedef LM LengthMap;
+    //The type of the length of the arcs.
+    typedef typename LM::Value Value;
+    /// Operation traits for Dijkstra algorithm.
+
+    /// It defines the used operation by the algorithm.
+    /// \see DijkstraDefaultOperationTraits
+    typedef DijkstraDefaultOperationTraits<Value> OperationTraits;
+    ///The heap type used by Dijkstra algorithm.
+
+    /// The cross reference type used by heap.
+
+    /// The cross reference type used by heap.
+    /// Usually it is \c Digraph::NodeMap<int>.
+    typedef typename Digraph::template NodeMap<int> HeapCrossRef;
+    ///Instantiates a HeapCrossRef.
+
+    ///This function instantiates a \ref HeapCrossRef. 
+    /// \param G is the digraph, to which we would like to define the 
+    /// HeapCrossRef.
+    /// \todo The digraph alone may be insufficient for the initialization
+    static HeapCrossRef *createHeapCrossRef(const GR &G) 
+    {
+      return new HeapCrossRef(G);
+    }
+    
+    ///The heap type used by Dijkstra algorithm.
+
+    ///The heap type used by Dijkstra algorithm.
+    ///
+    ///\sa BinHeap
+    ///\sa Dijkstra
+    typedef BinHeap<typename LM::Value, typename GR::template NodeMap<int>,
+		    std::less<Value> > Heap;
+
+    static Heap *createHeap(HeapCrossRef& R) 
+    {
+      return new Heap(R);
+    }
+
+    ///\brief The type of the map that stores the last
+    ///arcs of the shortest paths.
+    /// 
+    ///The type of the map that stores the last
+    ///arcs of the shortest paths.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef NullMap <typename GR::Node,typename GR::Arc> PredMap;
+    ///Instantiates a PredMap.
+ 
+    ///This function instantiates a \ref PredMap. 
+    ///\param g is the digraph, to which we would like to define the PredMap.
+    ///\todo The digraph alone may be insufficient for the initialization
+#ifdef DOXYGEN
+    static PredMap *createPredMap(const GR &g) 
+#else
+    static PredMap *createPredMap(const GR &) 
+#endif
+    {
+      return new PredMap();
+    }
+    ///The type of the map that stores whether a nodes is processed.
+ 
+    ///The type of the map that stores whether a nodes is processed.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///By default it is a NullMap.
+    ///\todo If it is set to a real map,
+    ///Dijkstra::processed() should read this.
+    ///\todo named parameter to set this type, function to read and write.
+    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
+    ///Instantiates a ProcessedMap.
+ 
+    ///This function instantiates a \ref ProcessedMap. 
+    ///\param g is the digraph, to which
+    ///we would like to define the \ref ProcessedMap
+#ifdef DOXYGEN
+    static ProcessedMap *createProcessedMap(const GR &g)
+#else
+    static ProcessedMap *createProcessedMap(const GR &)
+#endif
+    {
+      return new ProcessedMap();
+    }
+    ///The type of the map that stores the dists of the nodes.
+ 
+    ///The type of the map that stores the dists of the nodes.
+    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+    ///
+    typedef NullMap<typename Digraph::Node,typename LM::Value> DistMap;
+    ///Instantiates a DistMap.
+ 
+    ///This function instantiates a \ref DistMap. 
+    ///\param g is the digraph, to which we would like to define the \ref DistMap
+#ifdef DOXYGEN
+    static DistMap *createDistMap(const GR &g)
+#else
+    static DistMap *createDistMap(const GR &)
+#endif
+    {
+      return new DistMap();
+    }
+  };
+  
+  /// Default traits used by \ref DijkstraWizard
+
+  /// To make it easier to use Dijkstra algorithm
+  ///we have created a wizard class.
+  /// This \ref DijkstraWizard class needs default traits,
+  ///as well as the \ref Dijkstra class.
+  /// The \ref DijkstraWizardBase is a class to be the default traits of the
+  /// \ref DijkstraWizard class.
+  /// \todo More named parameters are required...
+  template<class GR,class LM>
+  class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LM>
+  {
+
+    typedef DijkstraWizardDefaultTraits<GR,LM> Base;
+  protected:
+    /// Type of the nodes in the digraph.
+    typedef typename Base::Digraph::Node Node;
+
+    /// Pointer to the underlying digraph.
+    void *_g;
+    /// Pointer to the length map
+    void *_length;
+    ///Pointer to the map of predecessors arcs.
+    void *_pred;
+    ///Pointer to the map of distances.
+    void *_dist;
+    ///Pointer to the source node.
+    Node _source;
+
+    public:
+    /// Constructor.
+    
+    /// This constructor does not require parameters, therefore it initiates
+    /// all of the attributes to default values (0, INVALID).
+    DijkstraWizardBase() : _g(0), _length(0), _pred(0),
+			   _dist(0), _source(INVALID) {}
+
+    /// Constructor.
+    
+    /// This constructor requires some parameters,
+    /// listed in the parameters list.
+    /// Others are initiated to 0.
+    /// \param g is the initial value of  \ref _g
+    /// \param l is the initial value of  \ref _length
+    /// \param s is the initial value of  \ref _source
+    DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
+      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
+      _length(reinterpret_cast<void*>(const_cast<LM*>(&l))), 
+      _pred(0), _dist(0), _source(s) {}
+
+  };
+  
+  /// A class to make the usage of Dijkstra algorithm easier
+
+  /// This class is created to make it easier to use Dijkstra algorithm.
+  /// It uses the functions and features of the plain \ref Dijkstra,
+  /// but it is much simpler to use it.
+  ///
+  /// Simplicity means that the way to change the types defined
+  /// in the traits class is based on functions that returns the new class
+  /// and not on templatable built-in classes.
+  /// When using the plain \ref Dijkstra
+  /// the new class with the modified type comes from
+  /// the original class by using the ::
+  /// operator. In the case of \ref DijkstraWizard only
+  /// a function have to be called and it will
+  /// return the needed class.
+  ///
+  /// It does not have own \ref run method. When its \ref run method is called
+  /// it initiates a plain \ref Dijkstra class, and calls the \ref 
+  /// Dijkstra::run method of it.
+  template<class TR>
+  class DijkstraWizard : public TR
+  {
+    typedef TR Base;
+
+    ///The type of the underlying digraph.
+    typedef typename TR::Digraph Digraph;
+    //\e
+    typedef typename Digraph::Node Node;
+    //\e
+    typedef typename Digraph::NodeIt NodeIt;
+    //\e
+    typedef typename Digraph::Arc Arc;
+    //\e
+    typedef typename Digraph::OutArcIt OutArcIt;
+    
+    ///The type of the map that stores the arc lengths.
+    typedef typename TR::LengthMap LengthMap;
+    ///The type of the length of the arcs.
+    typedef typename LengthMap::Value Value;
+    ///\brief The type of the map that stores the last
+    ///arcs of the shortest paths.
+    typedef typename TR::PredMap PredMap;
+    ///The type of the map that stores the dists of the nodes.
+    typedef typename TR::DistMap DistMap;
+    ///The heap type used by the dijkstra algorithm.
+    typedef typename TR::Heap Heap;
+  public:
+    /// Constructor.
+    DijkstraWizard() : TR() {}
+
+    /// Constructor that requires parameters.
+
+    /// Constructor that requires parameters.
+    /// These parameters will be the default values for the traits class.
+    DijkstraWizard(const Digraph &g,const LengthMap &l, Node s=INVALID) :
+      TR(g,l,s) {}
+
+    ///Copy constructor
+    DijkstraWizard(const TR &b) : TR(b) {}
+
+    ~DijkstraWizard() {}
+
+    ///Runs Dijkstra algorithm from a given node.
+    
+    ///Runs Dijkstra algorithm from a given node.
+    ///The node can be given by the \ref source function.
+    void run()
+    {
+      if(Base::_source==INVALID) throw UninitializedParameter();
+      Dijkstra<Digraph,LengthMap,TR> 
+	dij(*reinterpret_cast<const Digraph*>(Base::_g),
+            *reinterpret_cast<const LengthMap*>(Base::_length));
+      if(Base::_pred) dij.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
+      if(Base::_dist) dij.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
+      dij.run(Base::_source);
+    }
+
+    ///Runs Dijkstra algorithm from the given node.
+
+    ///Runs Dijkstra algorithm from the given node.
+    ///\param s is the given source.
+    void run(Node s)
+    {
+      Base::_source=s;
+      run();
+    }
+
+    template<class T>
+    struct DefPredMapBase : public Base {
+      typedef T PredMap;
+      static PredMap *createPredMap(const Digraph &) { return 0; };
+      DefPredMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting PredMap type
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting PredMap type
+    ///
+    template<class T>
+    DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) 
+    {
+      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return DijkstraWizard<DefPredMapBase<T> >(*this);
+    }
+    
+    template<class T>
+    struct DefDistMapBase : public Base {
+      typedef T DistMap;
+      static DistMap *createDistMap(const Digraph &) { return 0; };
+      DefDistMapBase(const TR &b) : TR(b) {}
+    };
+    
+    ///\brief \ref named-templ-param "Named parameter"
+    ///function for setting DistMap type
+    ///
+    /// \ref named-templ-param "Named parameter"
+    ///function for setting DistMap type
+    ///
+    template<class T>
+    DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) 
+    {
+      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
+      return DijkstraWizard<DefDistMapBase<T> >(*this);
+    }
+    
+    /// Sets the source node, from which the Dijkstra algorithm runs.
+
+    /// Sets the source node, from which the Dijkstra algorithm runs.
+    /// \param s is the source node.
+    DijkstraWizard<TR> &source(Node s) 
+    {
+      Base::_source=s;
+      return *this;
+    }
+    
+  };
+  
+  ///Function type interface for Dijkstra algorithm.
+
+  /// \ingroup shortest_path
+  ///Function type interface for Dijkstra algorithm.
+  ///
+  ///This function also has several
+  ///\ref named-templ-func-param "named parameters",
+  ///they are declared as the members of class \ref DijkstraWizard.
+  ///The following
+  ///example shows how to use these parameters.
+  ///\code
+  ///  dijkstra(g,length,source).predMap(preds).run();
+  ///\endcode
+  ///\warning Don't forget to put the \ref DijkstraWizard::run() "run()"
+  ///to the end of the parameter list.
+  ///\sa DijkstraWizard
+  ///\sa Dijkstra
+  template<class GR, class LM>
+  DijkstraWizard<DijkstraWizardBase<GR,LM> >
+  dijkstra(const GR &g,const LM &l,typename GR::Node s=INVALID)
+  {
+    return DijkstraWizard<DijkstraWizardBase<GR,LM> >(g,l,s);
+  }
+
+} //END OF NAMESPACE LEMON
+
+#endif
Index: lemon/graph_utils.h
===================================================================
--- lemon/graph_utils.h	(revision 100)
+++ lemon/graph_utils.h	(revision 100)
@@ -0,0 +1,3179 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_GRAPH_UTILS_H
+#define LEMON_GRAPH_UTILS_H
+
+#include <iterator>
+#include <vector>
+#include <map>
+#include <cmath>
+#include <algorithm>
+
+#include <lemon/bits/invalid.h>
+#include <lemon/bits/utility.h>
+#include <lemon/maps.h>
+#include <lemon/bits/traits.h>
+
+#include <lemon/bits/alteration_notifier.h>
+#include <lemon/bits/default_map.h>
+
+///\ingroup gutils
+///\file
+///\brief Digraph utilities.
+
+namespace lemon {
+
+  /// \addtogroup gutils
+  /// @{
+
+  ///Creates convenience typedefs for the digraph types and iterators
+
+  ///This \c \#define creates convenience typedefs for the following types
+  ///of \c Digraph: \c Node,  \c NodeIt, \c Arc, \c ArcIt, \c InArcIt,
+  ///\c OutArcIt
+  ///\note If \c G it a template parameter, it should be used in this way.
+  ///\code
+  ///  GRAPH_TYPEDEFS(typename G);
+  ///\endcode
+  ///
+  ///\warning There are no typedefs for the digraph maps because of the lack of
+  ///template typedefs in C++.
+#define GRAPH_TYPEDEFS(Digraph)				\
+  typedef Digraph::     Node      Node;			\
+    typedef Digraph::   NodeIt    NodeIt;			\
+    typedef Digraph::   Arc      Arc;			\
+    typedef Digraph::   ArcIt    ArcIt;			\
+    typedef Digraph:: InArcIt  InArcIt;			\
+    typedef Digraph::OutArcIt OutArcIt
+
+  ///Creates convenience typedefs for the graph types and iterators
+
+  ///This \c \#define creates the same convenience typedefs as defined by
+  ///\ref GRAPH_TYPEDEFS(Digraph) and three more, namely it creates
+  ///\c Edge, \c EdgeIt, \c IncArcIt,
+  ///
+  ///\note If \c G it a template parameter, it should be used in this way.
+  ///\code
+  ///  UGRAPH_TYPEDEFS(typename G);
+  ///\endcode
+  ///
+  ///\warning There are no typedefs for the digraph maps because of the lack of
+  ///template typedefs in C++.
+#define UGRAPH_TYPEDEFS(Digraph)				\
+  GRAPH_TYPEDEFS(Digraph);				\
+    typedef Digraph:: Edge   Edge;			\
+    typedef Digraph:: EdgeIt EdgeIt;			\
+    typedef Digraph:: IncArcIt   IncArcIt
+
+  ///\brief Creates convenience typedefs for the bipartite digraph 
+  ///types and iterators
+
+  ///This \c \#define creates the same convenience typedefs as defined by
+  ///\ref UGRAPH_TYPEDEFS(Digraph) and two more, namely it creates
+  ///\c RedIt, \c BlueIt, 
+  ///
+  ///\note If \c G it a template parameter, it should be used in this way.
+  ///\code
+  ///  BPUGRAPH_TYPEDEFS(typename G);
+  ///\endcode
+  ///
+  ///\warning There are no typedefs for the digraph maps because of the lack of
+  ///template typedefs in C++.
+#define BPUGRAPH_TYPEDEFS(Digraph)            \
+  UGRAPH_TYPEDEFS(Digraph);		    \
+    typedef Digraph::Red Red;             \
+    typedef Digraph::Blue Blue;             \
+    typedef Digraph::RedIt RedIt;	    \
+    typedef Digraph::BlueIt BlueIt
+
+  /// \brief Function to count the items in the digraph.
+  ///
+  /// This function counts the items (nodes, arcs etc) in the digraph.
+  /// The complexity of the function is O(n) because
+  /// it iterates on all of the items.
+
+  template <typename Digraph, typename Item>
+  inline int countItems(const Digraph& g) {
+    typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt;
+    int num = 0;
+    for (ItemIt it(g); it != INVALID; ++it) {
+      ++num;
+    }
+    return num;
+  }
+
+  // Node counting:
+
+  namespace _digraph_utils_bits {
+    
+    template <typename Digraph, typename Enable = void>
+    struct CountNodesSelector {
+      static int count(const Digraph &g) {
+        return countItems<Digraph, typename Digraph::Node>(g);
+      }
+    };
+
+    template <typename Digraph>
+    struct CountNodesSelector<
+      Digraph, typename 
+      enable_if<typename Digraph::NodeNumTag, void>::type> 
+    {
+      static int count(const Digraph &g) {
+        return g.nodeNum();
+      }
+    };    
+  }
+
+  /// \brief Function to count the nodes in the digraph.
+  ///
+  /// This function counts the nodes in the digraph.
+  /// The complexity of the function is O(n) but for some
+  /// digraph structures it is specialized to run in O(1).
+  ///
+  /// If the digraph contains a \e nodeNum() member function and a 
+  /// \e NodeNumTag tag then this function calls directly the member
+  /// function to query the cardinality of the node set.
+  template <typename Digraph>
+  inline int countNodes(const Digraph& g) {
+    return _digraph_utils_bits::CountNodesSelector<Digraph>::count(g);
+  }
+
+  namespace _digraph_utils_bits {
+    
+    template <typename Digraph, typename Enable = void>
+    struct CountRedsSelector {
+      static int count(const Digraph &g) {
+        return countItems<Digraph, typename Digraph::Red>(g);
+      }
+    };
+
+    template <typename Digraph>
+    struct CountRedsSelector<
+      Digraph, typename 
+      enable_if<typename Digraph::NodeNumTag, void>::type> 
+    {
+      static int count(const Digraph &g) {
+        return g.redNum();
+      }
+    };    
+  }
+
+  /// \brief Function to count the reds in the digraph.
+  ///
+  /// This function counts the reds in the digraph.
+  /// The complexity of the function is O(an) but for some
+  /// digraph structures it is specialized to run in O(1).
+  ///
+  /// If the digraph contains an \e redNum() member function and a 
+  /// \e NodeNumTag tag then this function calls directly the member
+  /// function to query the cardinality of the A-node set.
+  template <typename Digraph>
+  inline int countReds(const Digraph& g) {
+    return _digraph_utils_bits::CountRedsSelector<Digraph>::count(g);
+  }
+
+  namespace _digraph_utils_bits {
+    
+    template <typename Digraph, typename Enable = void>
+    struct CountBluesSelector {
+      static int count(const Digraph &g) {
+        return countItems<Digraph, typename Digraph::Blue>(g);
+      }
+    };
+
+    template <typename Digraph>
+    struct CountBluesSelector<
+      Digraph, typename 
+      enable_if<typename Digraph::NodeNumTag, void>::type> 
+    {
+      static int count(const Digraph &g) {
+        return g.blueNum();
+      }
+    };    
+  }
+
+  /// \brief Function to count the blues in the digraph.
+  ///
+  /// This function counts the blues in the digraph.
+  /// The complexity of the function is O(bn) but for some
+  /// digraph structures it is specialized to run in O(1).
+  ///
+  /// If the digraph contains a \e blueNum() member function and a 
+  /// \e NodeNumTag tag then this function calls directly the member
+  /// function to query the cardinality of the B-node set.
+  template <typename Digraph>
+  inline int countBlues(const Digraph& g) {
+    return _digraph_utils_bits::CountBluesSelector<Digraph>::count(g);
+  }
+
+
+  // Arc counting:
+
+  namespace _digraph_utils_bits {
+    
+    template <typename Digraph, typename Enable = void>
+    struct CountArcsSelector {
+      static int count(const Digraph &g) {
+        return countItems<Digraph, typename Digraph::Arc>(g);
+      }
+    };
+
+    template <typename Digraph>
+    struct CountArcsSelector<
+      Digraph, 
+      typename enable_if<typename Digraph::ArcNumTag, void>::type> 
+    {
+      static int count(const Digraph &g) {
+        return g.arcNum();
+      }
+    };    
+  }
+
+  /// \brief Function to count the arcs in the digraph.
+  ///
+  /// This function counts the arcs in the digraph.
+  /// The complexity of the function is O(e) but for some
+  /// digraph structures it is specialized to run in O(1).
+  ///
+  /// If the digraph contains a \e arcNum() member function and a 
+  /// \e ArcNumTag tag then this function calls directly the member
+  /// function to query the cardinality of the arc set.
+  template <typename Digraph>
+  inline int countArcs(const Digraph& g) {
+    return _digraph_utils_bits::CountArcsSelector<Digraph>::count(g);
+  }
+
+  // Undirected arc counting:
+  namespace _digraph_utils_bits {
+    
+    template <typename Digraph, typename Enable = void>
+    struct CountEdgesSelector {
+      static int count(const Digraph &g) {
+        return countItems<Digraph, typename Digraph::Edge>(g);
+      }
+    };
+
+    template <typename Digraph>
+    struct CountEdgesSelector<
+      Digraph, 
+      typename enable_if<typename Digraph::ArcNumTag, void>::type> 
+    {
+      static int count(const Digraph &g) {
+        return g.edgeNum();
+      }
+    };    
+  }
+
+  /// \brief Function to count the edges in the digraph.
+  ///
+  /// This function counts the edges in the digraph.
+  /// The complexity of the function is O(e) but for some
+  /// digraph structures it is specialized to run in O(1).
+  ///
+  /// If the digraph contains a \e edgeNum() member function and a 
+  /// \e ArcNumTag tag then this function calls directly the member
+  /// function to query the cardinality of the edge set.
+  template <typename Digraph>
+  inline int countEdges(const Digraph& g) {
+    return _digraph_utils_bits::CountEdgesSelector<Digraph>::count(g);
+
+  }
+
+
+  template <typename Digraph, typename DegIt>
+  inline int countNodeDegree(const Digraph& _g, const typename Digraph::Node& _n) {
+    int num = 0;
+    for (DegIt it(_g, _n); it != INVALID; ++it) {
+      ++num;
+    }
+    return num;
+  }
+
+  /// \brief Function to count the number of the out-arcs from node \c n.
+  ///
+  /// This function counts the number of the out-arcs from node \c n
+  /// in the digraph.  
+  template <typename Digraph>
+  inline int countOutArcs(const Digraph& _g,  const typename Digraph::Node& _n) {
+    return countNodeDegree<Digraph, typename Digraph::OutArcIt>(_g, _n);
+  }
+
+  /// \brief Function to count the number of the in-arcs to node \c n.
+  ///
+  /// This function counts the number of the in-arcs to node \c n
+  /// in the digraph.  
+  template <typename Digraph>
+  inline int countInArcs(const Digraph& _g,  const typename Digraph::Node& _n) {
+    return countNodeDegree<Digraph, typename Digraph::InArcIt>(_g, _n);
+  }
+
+  /// \brief Function to count the number of the inc-arcs to node \c n.
+  ///
+  /// This function counts the number of the inc-arcs to node \c n
+  /// in the digraph.  
+  template <typename Digraph>
+  inline int countIncArcs(const Digraph& _g,  const typename Digraph::Node& _n) {
+    return countNodeDegree<Digraph, typename Digraph::IncArcIt>(_g, _n);
+  }
+
+  namespace _digraph_utils_bits {
+    
+    template <typename Digraph, typename Enable = void>
+    struct FindArcSelector {
+      typedef typename Digraph::Node Node;
+      typedef typename Digraph::Arc Arc;
+      static Arc find(const Digraph &g, Node u, Node v, Arc e) {
+        if (e == INVALID) {
+          g.firstOut(e, u);
+        } else {
+          g.nextOut(e);
+        }
+        while (e != INVALID && g.target(e) != v) {
+          g.nextOut(e);
+        }
+        return e;
+      }
+    };
+
+    template <typename Digraph>
+    struct FindArcSelector<
+      Digraph, 
+      typename enable_if<typename Digraph::FindArcTag, void>::type> 
+    {
+      typedef typename Digraph::Node Node;
+      typedef typename Digraph::Arc Arc;
+      static Arc find(const Digraph &g, Node u, Node v, Arc prev) {
+        return g.findArc(u, v, prev);
+      }
+    };    
+  }
+
+  /// \brief Finds an arc between two nodes of a digraph.
+  ///
+  /// Finds an arc from node \c u to node \c v in digraph \c g.
+  ///
+  /// If \c prev is \ref INVALID (this is the default value), then
+  /// it finds the first arc from \c u to \c v. Otherwise it looks for
+  /// the next arc from \c u to \c v after \c prev.
+  /// \return The found arc or \ref INVALID if there is no such an arc.
+  ///
+  /// Thus you can iterate through each arc from \c u to \c v as it follows.
+  ///\code
+  /// for(Arc e=findArc(g,u,v);e!=INVALID;e=findArc(g,u,v,e)) {
+  ///   ...
+  /// }
+  ///\endcode
+  ///
+  ///\sa ArcLookUp
+  ///\sa AllArcLookUp
+  ///\sa DynArcLookUp
+  ///\sa ConArcIt
+  template <typename Digraph>
+  inline typename Digraph::Arc 
+  findArc(const Digraph &g, typename Digraph::Node u, typename Digraph::Node v,
+           typename Digraph::Arc prev = INVALID) {
+    return _digraph_utils_bits::FindArcSelector<Digraph>::find(g, u, v, prev);
+  }
+
+  /// \brief Iterator for iterating on arcs connected the same nodes.
+  ///
+  /// Iterator for iterating on arcs connected the same nodes. It is 
+  /// higher level interface for the findArc() function. You can
+  /// use it the following way:
+  ///\code
+  /// for (ConArcIt<Digraph> it(g, src, trg); it != INVALID; ++it) {
+  ///   ...
+  /// }
+  ///\endcode
+  /// 
+  ///\sa findArc()
+  ///\sa ArcLookUp
+  ///\sa AllArcLookUp
+  ///\sa DynArcLookUp
+  ///
+  /// \author Balazs Dezso 
+  template <typename _Digraph>
+  class ConArcIt : public _Digraph::Arc {
+  public:
+
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Parent;
+
+    typedef typename Digraph::Arc Arc;
+    typedef typename Digraph::Node Node;
+
+    /// \brief Constructor.
+    ///
+    /// Construct a new ConArcIt iterating on the arcs which
+    /// connects the \c u and \c v node.
+    ConArcIt(const Digraph& g, Node u, Node v) : digraph(g) {
+      Parent::operator=(findArc(digraph, u, v));
+    }
+
+    /// \brief Constructor.
+    ///
+    /// Construct a new ConArcIt which continues the iterating from 
+    /// the \c e arc.
+    ConArcIt(const Digraph& g, Arc e) : Parent(e), digraph(g) {}
+    
+    /// \brief Increment operator.
+    ///
+    /// It increments the iterator and gives back the next arc.
+    ConArcIt& operator++() {
+      Parent::operator=(findArc(digraph, digraph.source(*this), 
+				 digraph.target(*this), *this));
+      return *this;
+    }
+  private:
+    const Digraph& digraph;
+  };
+
+  namespace _digraph_utils_bits {
+    
+    template <typename Digraph, typename Enable = void>
+    struct FindEdgeSelector {
+      typedef typename Digraph::Node Node;
+      typedef typename Digraph::Edge Edge;
+      static Edge find(const Digraph &g, Node u, Node v, Edge e) {
+        bool b;
+        if (u != v) {
+          if (e == INVALID) {
+            g.firstInc(e, b, u);
+          } else {
+            b = g.source(e) == u;
+            g.nextInc(e, b);
+          }
+          while (e != INVALID && (b ? g.target(e) : g.source(e)) != v) {
+            g.nextInc(e, b);
+          }
+        } else {
+          if (e == INVALID) {
+            g.firstInc(e, b, u);
+          } else {
+            b = true;
+            g.nextInc(e, b);
+          }
+          while (e != INVALID && (!b || g.target(e) != v)) {
+            g.nextInc(e, b);
+          }
+        }
+        return e;
+      }
+    };
+
+    template <typename Digraph>
+    struct FindEdgeSelector<
+      Digraph, 
+      typename enable_if<typename Digraph::FindArcTag, void>::type> 
+    {
+      typedef typename Digraph::Node Node;
+      typedef typename Digraph::Edge Edge;
+      static Edge find(const Digraph &g, Node u, Node v, Edge prev) {
+        return g.findEdge(u, v, prev);
+      }
+    };    
+  }
+
+  /// \brief Finds an edge between two nodes of a digraph.
+  ///
+  /// Finds an edge from node \c u to node \c v in digraph \c g.
+  /// If the node \c u and node \c v is equal then each loop arc
+  /// will be enumerated.
+  ///
+  /// If \c prev is \ref INVALID (this is the default value), then
+  /// it finds the first arc from \c u to \c v. Otherwise it looks for
+  /// the next arc from \c u to \c v after \c prev.
+  /// \return The found arc or \ref INVALID if there is no such an arc.
+  ///
+  /// Thus you can iterate through each arc from \c u to \c v as it follows.
+  ///\code
+  /// for(Edge e = findEdge(g,u,v); e != INVALID; 
+  ///     e = findEdge(g,u,v,e)) {
+  ///   ...
+  /// }
+  ///\endcode
+  ///
+  ///\sa ConArcIt
+
+  template <typename Digraph>
+  inline typename Digraph::Edge 
+  findEdge(const Digraph &g, typename Digraph::Node u, typename Digraph::Node v,
+            typename Digraph::Edge p = INVALID) {
+    return _digraph_utils_bits::FindEdgeSelector<Digraph>::find(g, u, v, p);
+  }
+
+  /// \brief Iterator for iterating on edges connected the same nodes.
+  ///
+  /// Iterator for iterating on edges connected the same nodes. It is 
+  /// higher level interface for the findEdge() function. You can
+  /// use it the following way:
+  ///\code
+  /// for (ConEdgeIt<Digraph> it(g, src, trg); it != INVALID; ++it) {
+  ///   ...
+  /// }
+  ///\endcode
+  ///
+  ///\sa findEdge()
+  ///
+  /// \author Balazs Dezso 
+  template <typename _Digraph>
+  class ConEdgeIt : public _Digraph::Edge {
+  public:
+
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Edge Parent;
+
+    typedef typename Digraph::Edge Edge;
+    typedef typename Digraph::Node Node;
+
+    /// \brief Constructor.
+    ///
+    /// Construct a new ConEdgeIt iterating on the arcs which
+    /// connects the \c u and \c v node.
+    ConEdgeIt(const Digraph& g, Node u, Node v) : digraph(g) {
+      Parent::operator=(findEdge(digraph, u, v));
+    }
+
+    /// \brief Constructor.
+    ///
+    /// Construct a new ConEdgeIt which continues the iterating from 
+    /// the \c e arc.
+    ConEdgeIt(const Digraph& g, Edge e) : Parent(e), digraph(g) {}
+    
+    /// \brief Increment operator.
+    ///
+    /// It increments the iterator and gives back the next arc.
+    ConEdgeIt& operator++() {
+      Parent::operator=(findEdge(digraph, digraph.source(*this), 
+				      digraph.target(*this), *this));
+      return *this;
+    }
+  private:
+    const Digraph& digraph;
+  };
+
+  /// \brief Copy a map.
+  ///
+  /// This function copies the \c from map to the \c to map. It uses the
+  /// given iterator to iterate on the data structure and it uses the \c ref
+  /// mapping to convert the from's keys to the to's keys.
+  template <typename To, typename From, 
+	    typename ItemIt, typename Ref>	    
+  void copyMap(To& to, const From& from, 
+	       ItemIt it, const Ref& ref) {
+    for (; it != INVALID; ++it) {
+      to[ref[it]] = from[it];
+    }
+  }
+
+  /// \brief Copy the from map to the to map.
+  ///
+  /// Copy the \c from map to the \c to map. It uses the given iterator
+  /// to iterate on the data structure.
+  template <typename To, typename From, typename ItemIt>	    
+  void copyMap(To& to, const From& from, ItemIt it) {
+    for (; it != INVALID; ++it) {
+      to[it] = from[it];
+    }
+  }
+
+  namespace _digraph_utils_bits {
+
+    template <typename Digraph, typename Item, typename RefMap>
+    class MapCopyBase {
+    public:
+      virtual void copy(const Digraph& from, const RefMap& refMap) = 0;
+      
+      virtual ~MapCopyBase() {}
+    };
+
+    template <typename Digraph, typename Item, typename RefMap, 
+              typename ToMap, typename FromMap>
+    class MapCopy : public MapCopyBase<Digraph, Item, RefMap> {
+    public:
+
+      MapCopy(ToMap& tmap, const FromMap& map) 
+        : _tmap(tmap), _map(map) {}
+      
+      virtual void copy(const Digraph& digraph, const RefMap& refMap) {
+        typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt;
+        for (ItemIt it(digraph); it != INVALID; ++it) {
+          _tmap.set(refMap[it], _map[it]);
+        }
+      }
+
+    private:
+      ToMap& _tmap;
+      const FromMap& _map;
+    };
+
+    template <typename Digraph, typename Item, typename RefMap, typename It>
+    class ItemCopy : public MapCopyBase<Digraph, Item, RefMap> {
+    public:
+
+      ItemCopy(It& it, const Item& item) : _it(it), _item(item) {}
+      
+      virtual void copy(const Digraph&, const RefMap& refMap) {
+        _it = refMap[_item];
+      }
+
+    private:
+      It& _it;
+      Item _item;
+    };
+
+    template <typename Digraph, typename Item, typename RefMap, typename Ref>
+    class RefCopy : public MapCopyBase<Digraph, Item, RefMap> {
+    public:
+
+      RefCopy(Ref& map) : _map(map) {}
+      
+      virtual void copy(const Digraph& digraph, const RefMap& refMap) {
+        typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt;
+        for (ItemIt it(digraph); it != INVALID; ++it) {
+          _map.set(it, refMap[it]);
+        }
+      }
+
+    private:
+      Ref& _map;
+    };
+
+    template <typename Digraph, typename Item, typename RefMap, 
+              typename CrossRef>
+    class CrossRefCopy : public MapCopyBase<Digraph, Item, RefMap> {
+    public:
+
+      CrossRefCopy(CrossRef& cmap) : _cmap(cmap) {}
+      
+      virtual void copy(const Digraph& digraph, const RefMap& refMap) {
+        typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt;
+        for (ItemIt it(digraph); it != INVALID; ++it) {
+          _cmap.set(refMap[it], it);
+        }
+      }
+
+    private:
+      CrossRef& _cmap;
+    };
+
+    template <typename Digraph, typename Enable = void>
+    struct DigraphCopySelector {
+      template <typename From, typename NodeRefMap, typename ArcRefMap>
+      static void copy(Digraph &to, const From& from,
+                       NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) {
+        for (typename From::NodeIt it(from); it != INVALID; ++it) {
+          nodeRefMap[it] = to.addNode();
+        }
+        for (typename From::ArcIt it(from); it != INVALID; ++it) {
+          arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)], 
+                                          nodeRefMap[from.target(it)]);
+        }
+      }
+    };
+
+    template <typename Digraph>
+    struct DigraphCopySelector<
+      Digraph, 
+      typename enable_if<typename Digraph::BuildTag, void>::type> 
+    {
+      template <typename From, typename NodeRefMap, typename ArcRefMap>
+      static void copy(Digraph &to, const From& from,
+                       NodeRefMap& nodeRefMap, ArcRefMap& arcRefMap) {
+        to.build(from, nodeRefMap, arcRefMap);
+      }
+    };
+
+    template <typename Graph, typename Enable = void>
+    struct GraphCopySelector {
+      template <typename From, typename NodeRefMap, typename EdgeRefMap>
+      static void copy(Graph &to, const From& from,
+                       NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
+        for (typename From::NodeIt it(from); it != INVALID; ++it) {
+          nodeRefMap[it] = to.addNode();
+        }
+        for (typename From::EdgeIt it(from); it != INVALID; ++it) {
+          edgeRefMap[it] = to.addArc(nodeRefMap[from.source(it)], 
+				       nodeRefMap[from.target(it)]);
+        }
+      }
+    };
+
+    template <typename Graph>
+    struct GraphCopySelector<
+      Graph, 
+      typename enable_if<typename Graph::BuildTag, void>::type> 
+    {
+      template <typename From, typename NodeRefMap, typename EdgeRefMap>
+      static void copy(Graph &to, const From& from,
+                       NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
+        to.build(from, nodeRefMap, edgeRefMap);
+      }
+    };
+
+    template <typename BpGraph, typename Enable = void>
+    struct BpGraphCopySelector {
+      template <typename From, typename RedRefMap, 
+                typename BlueRefMap, typename EdgeRefMap>
+      static void copy(BpGraph &to, const From& from,
+                       RedRefMap& redRefMap, BlueRefMap& blueRefMap,
+                       EdgeRefMap& edgeRefMap) {
+        for (typename From::RedIt it(from); it != INVALID; ++it) {
+          redRefMap[it] = to.addRed();
+        }
+        for (typename From::BlueIt it(from); it != INVALID; ++it) {
+          blueRefMap[it] = to.addBlue();
+        }
+        for (typename From::EdgeIt it(from); it != INVALID; ++it) {
+          edgeRefMap[it] = to.addArc(redRefMap[from.red(it)], 
+                                           blueRefMap[from.blue(it)]);
+        }
+      }
+    };
+
+    template <typename BpGraph>
+    struct BpGraphCopySelector<
+      BpGraph, 
+      typename enable_if<typename BpGraph::BuildTag, void>::type> 
+    {
+      template <typename From, typename RedRefMap, 
+                typename BlueRefMap, typename EdgeRefMap>
+      static void copy(BpGraph &to, const From& from,
+                       RedRefMap& redRefMap, BlueRefMap& blueRefMap,
+                       EdgeRefMap& edgeRefMap) {
+        to.build(from, redRefMap, blueRefMap, edgeRefMap);
+      }
+    };
+    
+
+  }
+
+  /// \brief Class to copy a digraph.
+  ///
+  /// Class to copy a digraph to another digraph (duplicate a digraph). The
+  /// simplest way of using it is through the \c copyDigraph() function.
+  template <typename To, typename From>
+  class DigraphCopy {
+  private:
+
+    typedef typename From::Node Node;
+    typedef typename From::NodeIt NodeIt;
+    typedef typename From::Arc Arc;
+    typedef typename From::ArcIt ArcIt;
+
+    typedef typename To::Node TNode;
+    typedef typename To::Arc TArc;
+
+    typedef typename From::template NodeMap<TNode> NodeRefMap;
+    typedef typename From::template ArcMap<TArc> ArcRefMap;
+    
+    
+  public: 
+
+
+    /// \brief Constructor for the DigraphCopy.
+    ///
+    /// It copies the content of the \c _from digraph into the
+    /// \c _to digraph.
+    DigraphCopy(To& _to, const From& _from) 
+      : from(_from), to(_to) {}
+
+    /// \brief Destructor of the DigraphCopy
+    ///
+    /// Destructor of the DigraphCopy
+    ~DigraphCopy() {
+      for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
+        delete nodeMapCopies[i];
+      }
+      for (int i = 0; i < int(arcMapCopies.size()); ++i) {
+        delete arcMapCopies[i];
+      }
+
+    }
+
+    /// \brief Copies the node references into the given map.
+    ///
+    /// Copies the node references into the given map.
+    template <typename NodeRef>
+    DigraphCopy& nodeRef(NodeRef& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Node, 
+                              NodeRefMap, NodeRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the node cross references into the given map.
+    ///
+    ///  Copies the node cross references (reverse references) into
+    ///  the given map.
+    template <typename NodeCrossRef>
+    DigraphCopy& nodeCrossRef(NodeCrossRef& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Node,
+                              NodeRefMap, NodeCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's node type,
+    /// and the copied map's key type is the from digraph's node
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    DigraphCopy& nodeMap(ToMap& tmap, const FromMap& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Node, 
+                              NodeRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Make a copy of the given node.
+    ///
+    /// Make a copy of the given node.
+    DigraphCopy& node(TNode& tnode, const Node& snode) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Node, 
+                              NodeRefMap, TNode>(tnode, snode));
+      return *this;
+    }
+
+    /// \brief Copies the arc references into the given map.
+    ///
+    /// Copies the arc references into the given map.
+    template <typename ArcRef>
+    DigraphCopy& arcRef(ArcRef& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Arc, 
+                              ArcRefMap, ArcRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the arc cross references into the given map.
+    ///
+    ///  Copies the arc cross references (reverse references) into
+    ///  the given map.
+    template <typename ArcCrossRef>
+    DigraphCopy& arcCrossRef(ArcCrossRef& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Arc,
+                              ArcRefMap, ArcCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's arc type,
+    /// and the copied map's key type is the from digraph's arc
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    DigraphCopy& arcMap(ToMap& tmap, const FromMap& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Arc, 
+                              ArcRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Make a copy of the given arc.
+    ///
+    /// Make a copy of the given arc.
+    DigraphCopy& arc(TArc& tarc, const Arc& sarc) {
+      arcMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Arc, 
+                              ArcRefMap, TArc>(tarc, sarc));
+      return *this;
+    }
+
+    /// \brief Executes the copies.
+    ///
+    /// Executes the copies.
+    void run() {
+      NodeRefMap nodeRefMap(from);
+      ArcRefMap arcRefMap(from);
+      _digraph_utils_bits::DigraphCopySelector<To>::
+        copy(to, from, nodeRefMap, arcRefMap);
+      for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
+        nodeMapCopies[i]->copy(from, nodeRefMap);
+      }
+      for (int i = 0; i < int(arcMapCopies.size()); ++i) {
+        arcMapCopies[i]->copy(from, arcRefMap);
+      }      
+    }
+
+  protected:
+
+
+    const From& from;
+    To& to;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 
+    nodeMapCopies;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* > 
+    arcMapCopies;
+
+  };
+
+  /// \brief Copy a digraph to another digraph.
+  ///
+  /// Copy a digraph to another digraph.
+  /// The usage of the function:
+  /// 
+  ///\code
+  /// copyDigraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run();
+  ///\endcode
+  /// 
+  /// After the copy the \c nr map will contain the mapping from the
+  /// nodes of the \c from digraph to the nodes of the \c to digraph and
+  /// \c ecr will contain the mapping from the arcs of the \c to digraph
+  /// to the arcs of the \c from digraph.
+  ///
+  /// \see DigraphCopy 
+  template <typename To, typename From>
+  DigraphCopy<To, From> copyDigraph(To& to, const From& from) {
+    return DigraphCopy<To, From>(to, from);
+  }
+
+  /// \brief Class to copy an graph.
+  ///
+  /// Class to copy an graph to another digraph (duplicate a digraph).
+  /// The simplest way of using it is through the \c copyGraph() function.
+  template <typename To, typename From>
+  class GraphCopy {
+  private:
+
+    typedef typename From::Node Node;
+    typedef typename From::NodeIt NodeIt;
+    typedef typename From::Arc Arc;
+    typedef typename From::ArcIt ArcIt;
+    typedef typename From::Edge Edge;
+    typedef typename From::EdgeIt EdgeIt;
+
+    typedef typename To::Node TNode;
+    typedef typename To::Arc TArc;
+    typedef typename To::Edge TEdge;
+
+    typedef typename From::template NodeMap<TNode> NodeRefMap;
+    typedef typename From::template EdgeMap<TEdge> EdgeRefMap;
+
+    struct ArcRefMap {
+      ArcRefMap(const To& _to, const From& _from,
+                 const EdgeRefMap& _edge_ref, const NodeRefMap& _node_ref) 
+        : to(_to), from(_from), 
+          edge_ref(_edge_ref), node_ref(_node_ref) {}
+
+      typedef typename From::Arc Key;
+      typedef typename To::Arc Value;
+
+      Value operator[](const Key& key) const {
+        bool forward = 
+          (from.direction(key) == 
+           (node_ref[from.source(static_cast<const Edge&>(key))] == 
+            to.source(edge_ref[static_cast<const Edge&>(key)])));
+	return to.direct(edge_ref[key], forward); 
+      }
+      
+      const To& to;
+      const From& from;
+      const EdgeRefMap& edge_ref;
+      const NodeRefMap& node_ref;
+    };
+
+    
+  public: 
+
+
+    /// \brief Constructor for the DigraphCopy.
+    ///
+    /// It copies the content of the \c _from digraph into the
+    /// \c _to digraph.
+    GraphCopy(To& _to, const From& _from) 
+      : from(_from), to(_to) {}
+
+    /// \brief Destructor of the DigraphCopy
+    ///
+    /// Destructor of the DigraphCopy
+    ~GraphCopy() {
+      for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
+        delete nodeMapCopies[i];
+      }
+      for (int i = 0; i < int(arcMapCopies.size()); ++i) {
+        delete arcMapCopies[i];
+      }
+      for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
+        delete edgeMapCopies[i];
+      }
+
+    }
+
+    /// \brief Copies the node references into the given map.
+    ///
+    /// Copies the node references into the given map.
+    template <typename NodeRef>
+    GraphCopy& nodeRef(NodeRef& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Node, 
+                              NodeRefMap, NodeRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the node cross references into the given map.
+    ///
+    ///  Copies the node cross references (reverse references) into
+    ///  the given map.
+    template <typename NodeCrossRef>
+    GraphCopy& nodeCrossRef(NodeCrossRef& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Node,
+                              NodeRefMap, NodeCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's node type,
+    /// and the copied map's key type is the from digraph's node
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    GraphCopy& nodeMap(ToMap& tmap, const FromMap& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Node, 
+                              NodeRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Make a copy of the given node.
+    ///
+    /// Make a copy of the given node.
+    GraphCopy& node(TNode& tnode, const Node& snode) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Node, 
+                              NodeRefMap, TNode>(tnode, snode));
+      return *this;
+    }
+
+    /// \brief Copies the arc references into the given map.
+    ///
+    /// Copies the arc references into the given map.
+    template <typename ArcRef>
+    GraphCopy& arcRef(ArcRef& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Arc, 
+                              ArcRefMap, ArcRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the arc cross references into the given map.
+    ///
+    ///  Copies the arc cross references (reverse references) into
+    ///  the given map.
+    template <typename ArcCrossRef>
+    GraphCopy& arcCrossRef(ArcCrossRef& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Arc,
+                              ArcRefMap, ArcCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's arc type,
+    /// and the copied map's key type is the from digraph's arc
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    GraphCopy& arcMap(ToMap& tmap, const FromMap& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Arc, 
+                              ArcRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Make a copy of the given arc.
+    ///
+    /// Make a copy of the given arc.
+    GraphCopy& arc(TArc& tarc, const Arc& sarc) {
+      arcMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Arc, 
+                              ArcRefMap, TArc>(tarc, sarc));
+      return *this;
+    }
+
+    /// \brief Copies the edge references into the given map.
+    ///
+    /// Copies the edge references into the given map.
+    template <typename EdgeRef>
+    GraphCopy& edgeRef(EdgeRef& map) {
+      edgeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Edge, 
+                               EdgeRefMap, EdgeRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the edge cross references into the given map.
+    ///
+    /// Copies the edge cross references (reverse
+    /// references) into the given map.
+    template <typename EdgeCrossRef>
+    GraphCopy& edgeCrossRef(EdgeCrossRef& map) {
+      edgeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, 
+                               Edge, EdgeRefMap, EdgeCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's edge type,
+    /// and the copied map's key type is the from digraph's edge
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    GraphCopy& edgeMap(ToMap& tmap, const FromMap& map) {
+      edgeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Edge, 
+                               EdgeRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Make a copy of the given edge.
+    ///
+    /// Make a copy of the given edge.
+    GraphCopy& edge(TEdge& tedge, const Edge& sedge) {
+      edgeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Edge, 
+                               EdgeRefMap, TEdge>(tedge, sedge));
+      return *this;
+    }
+
+    /// \brief Executes the copies.
+    ///
+    /// Executes the copies.
+    void run() {
+      NodeRefMap nodeRefMap(from);
+      EdgeRefMap edgeRefMap(from);
+      ArcRefMap arcRefMap(to, from, edgeRefMap, nodeRefMap);
+      _digraph_utils_bits::GraphCopySelector<To>::
+        copy(to, from, nodeRefMap, edgeRefMap);
+      for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
+        nodeMapCopies[i]->copy(from, nodeRefMap);
+      }
+      for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
+        edgeMapCopies[i]->copy(from, edgeRefMap);
+      }
+      for (int i = 0; i < int(arcMapCopies.size()); ++i) {
+        arcMapCopies[i]->copy(from, arcRefMap);
+      }
+    }
+
+  private:
+    
+    const From& from;
+    To& to;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 
+    nodeMapCopies;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* > 
+    arcMapCopies;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 
+    edgeMapCopies;
+
+  };
+
+  /// \brief Copy an graph to another digraph.
+  ///
+  /// Copy an graph to another digraph.
+  /// The usage of the function:
+  /// 
+  ///\code
+  /// copyGraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run();
+  ///\endcode
+  /// 
+  /// After the copy the \c nr map will contain the mapping from the
+  /// nodes of the \c from digraph to the nodes of the \c to digraph and
+  /// \c ecr will contain the mapping from the arcs of the \c to digraph
+  /// to the arcs of the \c from digraph.
+  ///
+  /// \see GraphCopy 
+  template <typename To, typename From>
+  GraphCopy<To, From> 
+  copyGraph(To& to, const From& from) {
+    return GraphCopy<To, From>(to, from);
+  }
+
+  /// \brief Class to copy a bipartite digraph.
+  ///
+  /// Class to copy a bipartite digraph to another digraph
+  /// (duplicate a digraph).  The simplest way of using it is through
+  /// the \c copyBpGraph() function.
+  template <typename To, typename From>
+  class BpGraphCopy {
+  private:
+
+    typedef typename From::Node Node;
+    typedef typename From::Red Red;
+    typedef typename From::Blue Blue;
+    typedef typename From::NodeIt NodeIt;
+    typedef typename From::Arc Arc;
+    typedef typename From::ArcIt ArcIt;
+    typedef typename From::Edge Edge;
+    typedef typename From::EdgeIt EdgeIt;
+
+    typedef typename To::Node TNode;
+    typedef typename To::Arc TArc;
+    typedef typename To::Edge TEdge;
+
+    typedef typename From::template RedMap<TNode> RedRefMap;
+    typedef typename From::template BlueMap<TNode> BlueRefMap;
+    typedef typename From::template EdgeMap<TEdge> EdgeRefMap;
+
+    struct NodeRefMap {
+      NodeRefMap(const From& _from, const RedRefMap& _red_ref,
+                 const BlueRefMap& _blue_ref)
+        : from(_from), red_ref(_red_ref), blue_ref(_blue_ref) {}
+
+      typedef typename From::Node Key;
+      typedef typename To::Node Value;
+
+      Value operator[](const Key& key) const {
+	return from.red(key) ? red_ref[key] : blue_ref[key]; 
+      }
+      
+      const From& from;
+      const RedRefMap& red_ref;
+      const BlueRefMap& blue_ref;
+    };
+
+    struct ArcRefMap {
+      ArcRefMap(const To& _to, const From& _from,
+                 const EdgeRefMap& _edge_ref, const NodeRefMap& _node_ref) 
+        : to(_to), from(_from), 
+          edge_ref(_edge_ref), node_ref(_node_ref) {}
+
+      typedef typename From::Arc Key;
+      typedef typename To::Arc Value;
+
+      Value operator[](const Key& key) const {
+        bool forward = 
+          (from.direction(key) == 
+           (node_ref[from.source(static_cast<const Edge&>(key))] == 
+            to.source(edge_ref[static_cast<const Edge&>(key)])));
+	return to.direct(edge_ref[key], forward); 
+      }
+      
+      const To& to;
+      const From& from;
+      const EdgeRefMap& edge_ref;
+      const NodeRefMap& node_ref;
+    };
+    
+  public: 
+
+
+    /// \brief Constructor for the DigraphCopy.
+    ///
+    /// It copies the content of the \c _from digraph into the
+    /// \c _to digraph.
+    BpGraphCopy(To& _to, const From& _from) 
+      : from(_from), to(_to) {}
+
+    /// \brief Destructor of the DigraphCopy
+    ///
+    /// Destructor of the DigraphCopy
+    ~BpGraphCopy() {
+      for (int i = 0; i < int(redMapCopies.size()); ++i) {
+        delete redMapCopies[i];
+      }
+      for (int i = 0; i < int(blueMapCopies.size()); ++i) {
+        delete blueMapCopies[i];
+      }
+      for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
+        delete nodeMapCopies[i];
+      }
+      for (int i = 0; i < int(arcMapCopies.size()); ++i) {
+        delete arcMapCopies[i];
+      }
+      for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
+        delete edgeMapCopies[i];
+      }
+
+    }
+
+    /// \brief Copies the A-node references into the given map.
+    ///
+    /// Copies the A-node references into the given map.
+    template <typename RedRef>
+    BpGraphCopy& redRef(RedRef& map) {
+      redMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Red, 
+                               RedRefMap, RedRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the A-node cross references into the given map.
+    ///
+    /// Copies the A-node cross references (reverse references) into
+    /// the given map.
+    template <typename RedCrossRef>
+    BpGraphCopy& redCrossRef(RedCrossRef& map) {
+      redMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, 
+                               Red, RedRefMap, RedCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given A-node map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's node type,
+    /// and the copied map's key type is the from digraph's node
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    BpGraphCopy& redMap(ToMap& tmap, const FromMap& map) {
+      redMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Red, 
+                               RedRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Copies the B-node references into the given map.
+    ///
+    /// Copies the B-node references into the given map.
+    template <typename BlueRef>
+    BpGraphCopy& blueRef(BlueRef& map) {
+      blueMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Blue, 
+                               BlueRefMap, BlueRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the B-node cross references into the given map.
+    ///
+    ///  Copies the B-node cross references (reverse references) into
+    ///  the given map.
+    template <typename BlueCrossRef>
+    BpGraphCopy& blueCrossRef(BlueCrossRef& map) {
+      blueMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, 
+                              Blue, BlueRefMap, BlueCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given B-node map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's node type,
+    /// and the copied map's key type is the from digraph's node
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    BpGraphCopy& blueMap(ToMap& tmap, const FromMap& map) {
+      blueMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Blue, 
+                               BlueRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+    /// \brief Copies the node references into the given map.
+    ///
+    /// Copies the node references into the given map.
+    template <typename NodeRef>
+    BpGraphCopy& nodeRef(NodeRef& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Node, 
+                              NodeRefMap, NodeRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the node cross references into the given map.
+    ///
+    ///  Copies the node cross references (reverse references) into
+    ///  the given map.
+    template <typename NodeCrossRef>
+    BpGraphCopy& nodeCrossRef(NodeCrossRef& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Node,
+                              NodeRefMap, NodeCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's node type,
+    /// and the copied map's key type is the from digraph's node
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    BpGraphCopy& nodeMap(ToMap& tmap, const FromMap& map) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Node, 
+                              NodeRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Make a copy of the given node.
+    ///
+    /// Make a copy of the given node.
+    BpGraphCopy& node(TNode& tnode, const Node& snode) {
+      nodeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Node, 
+                              NodeRefMap, TNode>(tnode, snode));
+      return *this;
+    }
+
+    /// \brief Copies the arc references into the given map.
+    ///
+    /// Copies the arc references into the given map.
+    template <typename ArcRef>
+    BpGraphCopy& arcRef(ArcRef& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Arc, 
+                              ArcRefMap, ArcRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the arc cross references into the given map.
+    ///
+    ///  Copies the arc cross references (reverse references) into
+    ///  the given map.
+    template <typename ArcCrossRef>
+    BpGraphCopy& arcCrossRef(ArcCrossRef& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Arc,
+                              ArcRefMap, ArcCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's arc type,
+    /// and the copied map's key type is the from digraph's arc
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    BpGraphCopy& arcMap(ToMap& tmap, const FromMap& map) {
+      arcMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Arc, 
+                              ArcRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Make a copy of the given arc.
+    ///
+    /// Make a copy of the given arc.
+    BpGraphCopy& arc(TArc& tarc, const Arc& sarc) {
+      arcMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Arc, 
+                              ArcRefMap, TArc>(tarc, sarc));
+      return *this;
+    }
+
+    /// \brief Copies the edge references into the given map.
+    ///
+    /// Copies the edge references into the given map.
+    template <typename EdgeRef>
+    BpGraphCopy& edgeRef(EdgeRef& map) {
+      edgeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Edge, 
+                               EdgeRefMap, EdgeRef>(map));
+      return *this;
+    }
+
+    /// \brief Copies the edge cross references into the given map.
+    ///
+    /// Copies the edge cross references (reverse
+    /// references) into the given map.
+    template <typename EdgeCrossRef>
+    BpGraphCopy& edgeCrossRef(EdgeCrossRef& map) {
+      edgeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, 
+                               Edge, EdgeRefMap, EdgeCrossRef>(map));
+      return *this;
+    }
+
+    /// \brief Make copy of the given map.
+    ///
+    /// Makes copy of the given map for the newly created digraph. 
+    /// The new map's key type is the to digraph's edge type,
+    /// and the copied map's key type is the from digraph's edge
+    /// type.  
+    template <typename ToMap, typename FromMap>
+    BpGraphCopy& edgeMap(ToMap& tmap, const FromMap& map) {
+      edgeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Edge, 
+                               EdgeRefMap, ToMap, FromMap>(tmap, map));
+      return *this;
+    }
+
+    /// \brief Make a copy of the given edge.
+    ///
+    /// Make a copy of the given edge.
+    BpGraphCopy& edge(TEdge& tedge, const Edge& sedge) {
+      edgeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Edge, 
+                               EdgeRefMap, TEdge>(tedge, sedge));
+      return *this;
+    }
+
+    /// \brief Executes the copies.
+    ///
+    /// Executes the copies.
+    void run() {
+      RedRefMap redRefMap(from);
+      BlueRefMap blueRefMap(from);
+      NodeRefMap nodeRefMap(from, redRefMap, blueRefMap);
+      EdgeRefMap edgeRefMap(from);
+      ArcRefMap arcRefMap(to, from, edgeRefMap, nodeRefMap);
+      _digraph_utils_bits::BpGraphCopySelector<To>::
+        copy(to, from, redRefMap, blueRefMap, edgeRefMap);
+      for (int i = 0; i < int(redMapCopies.size()); ++i) {
+        redMapCopies[i]->copy(from, redRefMap);
+      }
+      for (int i = 0; i < int(blueMapCopies.size()); ++i) {
+        blueMapCopies[i]->copy(from, blueRefMap);
+      }
+      for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
+        nodeMapCopies[i]->copy(from, nodeRefMap);
+      }
+      for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
+        edgeMapCopies[i]->copy(from, edgeRefMap);
+      }
+      for (int i = 0; i < int(arcMapCopies.size()); ++i) {
+        arcMapCopies[i]->copy(from, arcRefMap);
+      }
+    }
+
+  private:
+    
+    const From& from;
+    To& to;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Red, RedRefMap>* > 
+    redMapCopies;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Blue, BlueRefMap>* > 
+    blueMapCopies;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 
+    nodeMapCopies;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* > 
+    arcMapCopies;
+
+    std::vector<_digraph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 
+    edgeMapCopies;
+
+  };
+
+  /// \brief Copy a bipartite digraph to another digraph.
+  ///
+  /// Copy a bipartite digraph to another digraph.
+  /// The usage of the function:
+  /// 
+  ///\code
+  /// copyBpGraph(trg, src).redRef(anr).arcCrossRef(ecr).run();
+  ///\endcode
+  /// 
+  /// After the copy the \c nr map will contain the mapping from the
+  /// nodes of the \c from digraph to the nodes of the \c to digraph and
+  /// \c ecr will contain the mapping from the arcs of the \c to digraph
+  /// to the arcs of the \c from digraph.
+  ///
+  /// \see BpGraphCopy
+  template <typename To, typename From>
+  BpGraphCopy<To, From> 
+  copyBpGraph(To& to, const From& from) {
+    return BpGraphCopy<To, From>(to, from);
+  }
+
+
+  /// @}
+
+  /// \addtogroup digraph_maps
+  /// @{
+
+  /// Provides an immutable and unique id for each item in the digraph.
+
+  /// The IdMap class provides a unique and immutable id for each item of the
+  /// same type (e.g. node) in the digraph. This id is <ul><li>\b unique:
+  /// different items (nodes) get different ids <li>\b immutable: the id of an
+  /// item (node) does not change (even if you delete other nodes).  </ul>
+  /// Through this map you get access (i.e. can read) the inner id values of
+  /// the items stored in the digraph. This map can be inverted with its member
+  /// class \c InverseMap.
+  ///
+  template <typename _Digraph, typename _Item>
+  class IdMap {
+  public:
+    typedef _Digraph Digraph;
+    typedef int Value;
+    typedef _Item Item;
+    typedef _Item Key;
+
+    /// \brief Constructor.
+    ///
+    /// Constructor of the map.
+    explicit IdMap(const Digraph& _digraph) : digraph(&_digraph) {}
+
+    /// \brief Gives back the \e id of the item.
+    ///
+    /// Gives back the immutable and unique \e id of the item.
+    int operator[](const Item& item) const { return digraph->id(item);}
+
+    /// \brief Gives back the item by its id.
+    ///
+    /// Gives back the item by its id.
+    Item operator()(int id) { return digraph->fromId(id, Item()); }
+
+  private:
+    const Digraph* digraph;
+
+  public:
+
+    /// \brief The class represents the inverse of its owner (IdMap).
+    ///
+    /// The class represents the inverse of its owner (IdMap).
+    /// \see inverse()
+    class InverseMap {
+    public:
+
+      /// \brief Constructor.
+      ///
+      /// Constructor for creating an id-to-item map.
+      explicit InverseMap(const Digraph& _digraph) : digraph(&_digraph) {}
+
+      /// \brief Constructor.
+      ///
+      /// Constructor for creating an id-to-item map.
+      explicit InverseMap(const IdMap& idMap) : digraph(idMap.digraph) {}
+
+      /// \brief Gives back the given item from its id.
+      ///
+      /// Gives back the given item from its id.
+      /// 
+      Item operator[](int id) const { return digraph->fromId(id, Item());}
+
+    private:
+      const Digraph* digraph;
+    };
+
+    /// \brief Gives back the inverse of the map.
+    ///
+    /// Gives back the inverse of the IdMap.
+    InverseMap inverse() const { return InverseMap(*digraph);} 
+
+  };
+
+  
+  /// \brief General invertable digraph-map type.
+
+  /// This type provides simple invertable digraph-maps. 
+  /// The InvertableMap wraps an arbitrary ReadWriteMap 
+  /// and if a key is set to a new value then store it
+  /// in the inverse map.
+  ///
+  /// The values of the map can be accessed
+  /// with stl compatible forward iterator.
+  ///
+  /// \param _Digraph The digraph type.
+  /// \param _Item The item type of the digraph.
+  /// \param _Value The value type of the map.
+  ///
+  /// \see IterableValueMap
+  template <typename _Digraph, typename _Item, typename _Value>
+  class InvertableMap : protected DefaultMap<_Digraph, _Item, _Value> {
+  private:
+    
+    typedef DefaultMap<_Digraph, _Item, _Value> Map;
+    typedef _Digraph Digraph;
+
+    typedef std::map<_Value, _Item> Container;
+    Container invMap;    
+
+  public:
+ 
+    /// The key type of InvertableMap (Node, Arc, Edge).
+    typedef typename Map::Key Key;
+    /// The value type of the InvertableMap.
+    typedef typename Map::Value Value;
+
+
+
+    /// \brief Constructor.
+    ///
+    /// Construct a new InvertableMap for the digraph.
+    ///
+    explicit InvertableMap(const Digraph& digraph) : Map(digraph) {} 
+
+    /// \brief Forward iterator for values.
+    ///
+    /// This iterator is an stl compatible forward
+    /// iterator on the values of the map. The values can
+    /// be accessed in the [beginValue, endValue) range.
+    ///
+    class ValueIterator 
+      : public std::iterator<std::forward_iterator_tag, Value> {
+      friend class InvertableMap;
+    private:
+      ValueIterator(typename Container::const_iterator _it) 
+        : it(_it) {}
+    public:
+      
+      ValueIterator() {}
+
+      ValueIterator& operator++() { ++it; return *this; }
+      ValueIterator operator++(int) { 
+        ValueIterator tmp(*this); 
+        operator++();
+        return tmp; 
+      }
+
+      const Value& operator*() const { return it->first; }
+      const Value* operator->() const { return &(it->first); }
+
+      bool operator==(ValueIterator jt) const { return it == jt.it; }
+      bool operator!=(ValueIterator jt) const { return it != jt.it; }
+      
+    private:
+      typename Container::const_iterator it;
+    };
+
+    /// \brief Returns an iterator to the first value.
+    ///
+    /// Returns an stl compatible iterator to the 
+    /// first value of the map. The values of the
+    /// map can be accessed in the [beginValue, endValue)
+    /// range.
+    ValueIterator beginValue() const {
+      return ValueIterator(invMap.begin());
+    }
+
+    /// \brief Returns an iterator after the last value.
+    ///
+    /// Returns an stl compatible iterator after the 
+    /// last value of the map. The values of the
+    /// map can be accessed in the [beginValue, endValue)
+    /// range.
+    ValueIterator endValue() const {
+      return ValueIterator(invMap.end());
+    }
+    
+    /// \brief The setter function of the map.
+    ///
+    /// Sets the mapped value.
+    void set(const Key& key, const Value& val) {
+      Value oldval = Map::operator[](key);
+      typename Container::iterator it = invMap.find(oldval);
+      if (it != invMap.end() && it->second == key) {
+	invMap.erase(it);
+      }      
+      invMap.insert(make_pair(val, key));
+      Map::set(key, val);
+    }
+
+    /// \brief The getter function of the map.
+    ///
+    /// It gives back the value associated with the key.
+    typename MapTraits<Map>::ConstReturnValue 
+    operator[](const Key& key) const {
+      return Map::operator[](key);
+    }
+
+    /// \brief Gives back the item by its value.
+    ///
+    /// Gives back the item by its value.
+    Key operator()(const Value& key) const {
+      typename Container::const_iterator it = invMap.find(key);
+      return it != invMap.end() ? it->second : INVALID;
+    }
+
+  protected:
+
+    /// \brief Erase the key from the map.
+    ///
+    /// Erase the key to the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void erase(const Key& key) {
+      Value val = Map::operator[](key);
+      typename Container::iterator it = invMap.find(val);
+      if (it != invMap.end() && it->second == key) {
+	invMap.erase(it);
+      }
+      Map::erase(key);
+    }
+
+    /// \brief Erase more keys from the map.
+    ///
+    /// Erase more keys from the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void erase(const std::vector<Key>& keys) {
+      for (int i = 0; i < int(keys.size()); ++i) {
+	Value val = Map::operator[](keys[i]);
+	typename Container::iterator it = invMap.find(val);
+	if (it != invMap.end() && it->second == keys[i]) {
+	  invMap.erase(it);
+	}
+      }
+      Map::erase(keys);
+    }
+
+    /// \brief Clear the keys from the map and inverse map.
+    ///
+    /// Clear the keys from the map and inverse map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void clear() {
+      invMap.clear();
+      Map::clear();
+    }
+
+  public:
+
+    /// \brief The inverse map type.
+    ///
+    /// The inverse of this map. The subscript operator of the map
+    /// gives back always the item what was last assigned to the value. 
+    class InverseMap {
+    public:
+      /// \brief Constructor of the InverseMap.
+      ///
+      /// Constructor of the InverseMap.
+      explicit InverseMap(const InvertableMap& _inverted) 
+        : inverted(_inverted) {}
+
+      /// The value type of the InverseMap.
+      typedef typename InvertableMap::Key Value;
+      /// The key type of the InverseMap.
+      typedef typename InvertableMap::Value Key; 
+
+      /// \brief Subscript operator. 
+      ///
+      /// Subscript operator. It gives back always the item 
+      /// what was last assigned to the value.
+      Value operator[](const Key& key) const {
+	return inverted(key);
+      }
+      
+    private:
+      const InvertableMap& inverted;
+    };
+
+    /// \brief It gives back the just readable inverse map.
+    ///
+    /// It gives back the just readable inverse map.
+    InverseMap inverse() const {
+      return InverseMap(*this);
+    } 
+
+
+    
+  };
+
+  /// \brief Provides a mutable, continuous and unique descriptor for each 
+  /// item in the digraph.
+  ///
+  /// The DescriptorMap class provides a unique and continuous (but mutable)
+  /// descriptor (id) for each item of the same type (e.g. node) in the
+  /// digraph. This id is <ul><li>\b unique: different items (nodes) get
+  /// different ids <li>\b continuous: the range of the ids is the set of
+  /// integers between 0 and \c n-1, where \c n is the number of the items of
+  /// this type (e.g. nodes) (so the id of a node can change if you delete an
+  /// other node, i.e. this id is mutable).  </ul> This map can be inverted
+  /// with its member class \c InverseMap.
+  ///
+  /// \param _Digraph The digraph class the \c DescriptorMap belongs to.
+  /// \param _Item The Item is the Key of the Map. It may be Node, Arc or 
+  /// Edge.
+  template <typename _Digraph, typename _Item>
+  class DescriptorMap : protected DefaultMap<_Digraph, _Item, int> {
+
+    typedef _Item Item;
+    typedef DefaultMap<_Digraph, _Item, int> Map;
+
+  public:
+    /// The digraph class of DescriptorMap.
+    typedef _Digraph Digraph;
+
+    /// The key type of DescriptorMap (Node, Arc, Edge).
+    typedef typename Map::Key Key;
+    /// The value type of DescriptorMap.
+    typedef typename Map::Value Value;
+
+    /// \brief Constructor.
+    ///
+    /// Constructor for descriptor map.
+    explicit DescriptorMap(const Digraph& _digraph) : Map(_digraph) {
+      Item it;
+      const typename Map::Notifier* nf = Map::notifier(); 
+      for (nf->first(it); it != INVALID; nf->next(it)) {
+	Map::set(it, invMap.size());
+	invMap.push_back(it);	
+      }      
+    }
+
+  protected:
+
+    /// \brief Add a new key to the map.
+    ///
+    /// Add a new key to the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void add(const Item& item) {
+      Map::add(item);
+      Map::set(item, invMap.size());
+      invMap.push_back(item);
+    }
+
+    /// \brief Add more new keys to the map.
+    ///
+    /// Add more new keys to the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void add(const std::vector<Item>& items) {
+      Map::add(items);
+      for (int i = 0; i < int(items.size()); ++i) {
+	Map::set(items[i], invMap.size());
+	invMap.push_back(items[i]);
+      }
+    }
+
+    /// \brief Erase the key from the map.
+    ///
+    /// Erase the key from the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void erase(const Item& item) {
+      Map::set(invMap.back(), Map::operator[](item));
+      invMap[Map::operator[](item)] = invMap.back();
+      invMap.pop_back();
+      Map::erase(item);
+    }
+
+    /// \brief Erase more keys from the map.
+    ///
+    /// Erase more keys from the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void erase(const std::vector<Item>& items) {
+      for (int i = 0; i < int(items.size()); ++i) {
+	Map::set(invMap.back(), Map::operator[](items[i]));
+	invMap[Map::operator[](items[i])] = invMap.back();
+	invMap.pop_back();
+      }
+      Map::erase(items);
+    }
+
+    /// \brief Build the unique map.
+    ///
+    /// Build the unique map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void build() {
+      Map::build();
+      Item it;
+      const typename Map::Notifier* nf = Map::notifier(); 
+      for (nf->first(it); it != INVALID; nf->next(it)) {
+	Map::set(it, invMap.size());
+	invMap.push_back(it);	
+      }      
+    }
+    
+    /// \brief Clear the keys from the map.
+    ///
+    /// Clear the keys from the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void clear() {
+      invMap.clear();
+      Map::clear();
+    }
+
+  public:
+
+    /// \brief Returns the maximal value plus one.
+    ///
+    /// Returns the maximal value plus one in the map.
+    unsigned int size() const {
+      return invMap.size();
+    }
+
+    /// \brief Swaps the position of the two items in the map.
+    ///
+    /// Swaps the position of the two items in the map.
+    void swap(const Item& p, const Item& q) {
+      int pi = Map::operator[](p);
+      int qi = Map::operator[](q);
+      Map::set(p, qi);
+      invMap[qi] = p;
+      Map::set(q, pi);
+      invMap[pi] = q;
+    }
+
+    /// \brief Gives back the \e descriptor of the item.
+    ///
+    /// Gives back the mutable and unique \e descriptor of the map.
+    int operator[](const Item& item) const {
+      return Map::operator[](item);
+    }
+
+    /// \brief Gives back the item by its descriptor.
+    ///
+    /// Gives back th item by its descriptor.
+    Item operator()(int id) const {
+      return invMap[id];
+    }
+    
+  private:
+
+    typedef std::vector<Item> Container;
+    Container invMap;
+
+  public:
+    /// \brief The inverse map type of DescriptorMap.
+    ///
+    /// The inverse map type of DescriptorMap.
+    class InverseMap {
+    public:
+      /// \brief Constructor of the InverseMap.
+      ///
+      /// Constructor of the InverseMap.
+      explicit InverseMap(const DescriptorMap& _inverted) 
+	: inverted(_inverted) {}
+
+
+      /// The value type of the InverseMap.
+      typedef typename DescriptorMap::Key Value;
+      /// The key type of the InverseMap.
+      typedef typename DescriptorMap::Value Key; 
+
+      /// \brief Subscript operator. 
+      ///
+      /// Subscript operator. It gives back the item 
+      /// that the descriptor belongs to currently.
+      Value operator[](const Key& key) const {
+	return inverted(key);
+      }
+
+      /// \brief Size of the map.
+      ///
+      /// Returns the size of the map.
+      unsigned int size() const {
+	return inverted.size();
+      }
+      
+    private:
+      const DescriptorMap& inverted;
+    };
+
+    /// \brief Gives back the inverse of the map.
+    ///
+    /// Gives back the inverse of the map.
+    const InverseMap inverse() const {
+      return InverseMap(*this);
+    }
+  };
+
+  /// \brief Returns the source of the given arc.
+  ///
+  /// The SourceMap gives back the source Node of the given arc. 
+  /// \see TargetMap
+  /// \author Balazs Dezso
+  template <typename Digraph>
+  class SourceMap {
+  public:
+
+    typedef typename Digraph::Node Value;
+    typedef typename Digraph::Arc Key;
+
+    /// \brief Constructor
+    ///
+    /// Constructor
+    /// \param _digraph The digraph that the map belongs to.
+    explicit SourceMap(const Digraph& _digraph) : digraph(_digraph) {}
+
+    /// \brief The subscript operator.
+    ///
+    /// The subscript operator.
+    /// \param arc The arc 
+    /// \return The source of the arc 
+    Value operator[](const Key& arc) const {
+      return digraph.source(arc);
+    }
+
+  private:
+    const Digraph& digraph;
+  };
+
+  /// \brief Returns a \ref SourceMap class.
+  ///
+  /// This function just returns an \ref SourceMap class.
+  /// \relates SourceMap
+  template <typename Digraph>
+  inline SourceMap<Digraph> sourceMap(const Digraph& digraph) {
+    return SourceMap<Digraph>(digraph);
+  } 
+
+  /// \brief Returns the target of the given arc.
+  ///
+  /// The TargetMap gives back the target Node of the given arc. 
+  /// \see SourceMap
+  /// \author Balazs Dezso
+  template <typename Digraph>
+  class TargetMap {
+  public:
+
+    typedef typename Digraph::Node Value;
+    typedef typename Digraph::Arc Key;
+
+    /// \brief Constructor
+    ///
+    /// Constructor
+    /// \param _digraph The digraph that the map belongs to.
+    explicit TargetMap(const Digraph& _digraph) : digraph(_digraph) {}
+
+    /// \brief The subscript operator.
+    ///
+    /// The subscript operator.
+    /// \param e The arc 
+    /// \return The target of the arc 
+    Value operator[](const Key& e) const {
+      return digraph.target(e);
+    }
+
+  private:
+    const Digraph& digraph;
+  };
+
+  /// \brief Returns a \ref TargetMap class.
+  ///
+  /// This function just returns a \ref TargetMap class.
+  /// \relates TargetMap
+  template <typename Digraph>
+  inline TargetMap<Digraph> targetMap(const Digraph& digraph) {
+    return TargetMap<Digraph>(digraph);
+  }
+
+  /// \brief Returns the "forward" directed arc view of an edge.
+  ///
+  /// Returns the "forward" directed arc view of an edge.
+  /// \see BackwardMap
+  /// \author Balazs Dezso
+  template <typename Digraph>
+  class ForwardMap {
+  public:
+
+    typedef typename Digraph::Arc Value;
+    typedef typename Digraph::Edge Key;
+
+    /// \brief Constructor
+    ///
+    /// Constructor
+    /// \param _digraph The digraph that the map belongs to.
+    explicit ForwardMap(const Digraph& _digraph) : digraph(_digraph) {}
+
+    /// \brief The subscript operator.
+    ///
+    /// The subscript operator.
+    /// \param key An edge 
+    /// \return The "forward" directed arc view of edge 
+    Value operator[](const Key& key) const {
+      return digraph.direct(key, true);
+    }
+
+  private:
+    const Digraph& digraph;
+  };
+
+  /// \brief Returns a \ref ForwardMap class.
+  ///
+  /// This function just returns an \ref ForwardMap class.
+  /// \relates ForwardMap
+  template <typename Digraph>
+  inline ForwardMap<Digraph> forwardMap(const Digraph& digraph) {
+    return ForwardMap<Digraph>(digraph);
+  }
+
+  /// \brief Returns the "backward" directed arc view of an edge.
+  ///
+  /// Returns the "backward" directed arc view of an edge.
+  /// \see ForwardMap
+  /// \author Balazs Dezso
+  template <typename Digraph>
+  class BackwardMap {
+  public:
+
+    typedef typename Digraph::Arc Value;
+    typedef typename Digraph::Edge Key;
+
+    /// \brief Constructor
+    ///
+    /// Constructor
+    /// \param _digraph The digraph that the map belongs to.
+    explicit BackwardMap(const Digraph& _digraph) : digraph(_digraph) {}
+
+    /// \brief The subscript operator.
+    ///
+    /// The subscript operator.
+    /// \param key An edge 
+    /// \return The "backward" directed arc view of edge 
+    Value operator[](const Key& key) const {
+      return digraph.direct(key, false);
+    }
+
+  private:
+    const Digraph& digraph;
+  };
+
+  /// \brief Returns a \ref BackwardMap class
+
+  /// This function just returns a \ref BackwardMap class.
+  /// \relates BackwardMap
+  template <typename Digraph>
+  inline BackwardMap<Digraph> backwardMap(const Digraph& digraph) {
+    return BackwardMap<Digraph>(digraph);
+  }
+
+  /// \brief Potential difference map
+  ///
+  /// If there is an potential map on the nodes then we
+  /// can get an arc map as we get the substraction of the
+  /// values of the target and source.
+  template <typename Digraph, typename NodeMap>
+  class PotentialDifferenceMap {
+  public:
+    typedef typename Digraph::Arc Key;
+    typedef typename NodeMap::Value Value;
+
+    /// \brief Constructor
+    ///
+    /// Contructor of the map
+    explicit PotentialDifferenceMap(const Digraph& _digraph, 
+                                    const NodeMap& _potential) 
+      : digraph(_digraph), potential(_potential) {}
+
+    /// \brief Const subscription operator
+    ///
+    /// Const subscription operator
+    Value operator[](const Key& arc) const {
+      return potential[digraph.target(arc)] - potential[digraph.source(arc)];
+    }
+
+  private:
+    const Digraph& digraph;
+    const NodeMap& potential;
+  };
+
+  /// \brief Returns a PotentialDifferenceMap.
+  ///
+  /// This function just returns a PotentialDifferenceMap.
+  /// \relates PotentialDifferenceMap
+  template <typename Digraph, typename NodeMap>
+  PotentialDifferenceMap<Digraph, NodeMap> 
+  potentialDifferenceMap(const Digraph& digraph, const NodeMap& potential) {
+    return PotentialDifferenceMap<Digraph, NodeMap>(digraph, potential);
+  }
+
+  /// \brief Map of the node in-degrees.
+  ///
+  /// This map returns the in-degree of a node. Once it is constructed,
+  /// the degrees are stored in a standard NodeMap, so each query is done
+  /// in constant time. On the other hand, the values are updated automatically
+  /// whenever the digraph changes.
+  ///
+  /// \warning Besides addNode() and addArc(), a digraph structure may provide
+  /// alternative ways to modify the digraph. The correct behavior of InDegMap
+  /// is not guarantied if these additional features are used. For example
+  /// the functions \ref ListDigraph::changeSource() "changeSource()",
+  /// \ref ListDigraph::changeTarget() "changeTarget()" and
+  /// \ref ListDigraph::reverseArc() "reverseArc()"
+  /// of \ref ListDigraph will \e not update the degree values correctly.
+  ///
+  /// \sa OutDegMap
+
+  template <typename _Digraph>
+  class InDegMap  
+    : protected ItemSetTraits<_Digraph, typename _Digraph::Arc>
+      ::ItemNotifier::ObserverBase {
+
+  public:
+    
+    typedef _Digraph Digraph;
+    typedef int Value;
+    typedef typename Digraph::Node Key;
+
+    typedef typename ItemSetTraits<_Digraph, typename _Digraph::Arc>
+    ::ItemNotifier::ObserverBase Parent;
+
+  private:
+
+    class AutoNodeMap : public DefaultMap<_Digraph, Key, int> {
+    public:
+
+      typedef DefaultMap<_Digraph, Key, int> Parent;
+      typedef typename Parent::Digraph Digraph;
+
+      AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {}
+      
+      virtual void add(const Key& key) {
+	Parent::add(key);
+	Parent::set(key, 0);
+      }
+
+      virtual void add(const std::vector<Key>& keys) {
+	Parent::add(keys);
+	for (int i = 0; i < int(keys.size()); ++i) {
+	  Parent::set(keys[i], 0);
+	}
+      }
+
+      virtual void build() {
+	Parent::build();
+	Key it;
+	typename Parent::Notifier* nf = Parent::notifier();
+	for (nf->first(it); it != INVALID; nf->next(it)) {
+	  Parent::set(it, 0);
+	}
+      }
+    };
+
+  public:
+
+    /// \brief Constructor.
+    ///
+    /// Constructor for creating in-degree map.
+    explicit InDegMap(const Digraph& _digraph) : digraph(_digraph), deg(_digraph) {
+      Parent::attach(digraph.notifier(typename _Digraph::Arc()));
+      
+      for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {
+	deg[it] = countInArcs(digraph, it);
+      }
+    }
+    
+    /// Gives back the in-degree of a Node.
+    int operator[](const Key& key) const {
+      return deg[key];
+    }
+
+  protected:
+    
+    typedef typename Digraph::Arc Arc;
+
+    virtual void add(const Arc& arc) {
+      ++deg[digraph.target(arc)];
+    }
+
+    virtual void add(const std::vector<Arc>& arcs) {
+      for (int i = 0; i < int(arcs.size()); ++i) {
+        ++deg[digraph.target(arcs[i])];
+      }
+    }
+
+    virtual void erase(const Arc& arc) {
+      --deg[digraph.target(arc)];
+    }
+
+    virtual void erase(const std::vector<Arc>& arcs) {
+      for (int i = 0; i < int(arcs.size()); ++i) {
+        --deg[digraph.target(arcs[i])];
+      }
+    }
+
+    virtual void build() {
+      for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {
+	deg[it] = countInArcs(digraph, it);
+      }      
+    }
+
+    virtual void clear() {
+      for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {
+	deg[it] = 0;
+      }
+    }
+  private:
+    
+    const _Digraph& digraph;
+    AutoNodeMap deg;
+  };
+
+  /// \brief Map of the node out-degrees.
+  ///
+  /// This map returns the out-degree of a node. Once it is constructed,
+  /// the degrees are stored in a standard NodeMap, so each query is done
+  /// in constant time. On the other hand, the values are updated automatically
+  /// whenever the digraph changes.
+  ///
+  /// \warning Besides addNode() and addArc(), a digraph structure may provide
+  /// alternative ways to modify the digraph. The correct behavior of OutDegMap
+  /// is not guarantied if these additional features are used. For example
+  /// the functions \ref ListDigraph::changeSource() "changeSource()",
+  /// \ref ListDigraph::changeTarget() "changeTarget()" and
+  /// \ref ListDigraph::reverseArc() "reverseArc()"
+  /// of \ref ListDigraph will \e not update the degree values correctly.
+  ///
+  /// \sa InDegMap
+
+  template <typename _Digraph>
+  class OutDegMap  
+    : protected ItemSetTraits<_Digraph, typename _Digraph::Arc>
+      ::ItemNotifier::ObserverBase {
+
+  public:
+
+    typedef typename ItemSetTraits<_Digraph, typename _Digraph::Arc>
+    ::ItemNotifier::ObserverBase Parent;
+    
+    typedef _Digraph Digraph;
+    typedef int Value;
+    typedef typename Digraph::Node Key;
+
+  private:
+
+    class AutoNodeMap : public DefaultMap<_Digraph, Key, int> {
+    public:
+
+      typedef DefaultMap<_Digraph, Key, int> Parent;
+      typedef typename Parent::Digraph Digraph;
+
+      AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {}
+      
+      virtual void add(const Key& key) {
+	Parent::add(key);
+	Parent::set(key, 0);
+      }
+      virtual void add(const std::vector<Key>& keys) {
+	Parent::add(keys);
+	for (int i = 0; i < int(keys.size()); ++i) {
+	  Parent::set(keys[i], 0);
+	}
+      }
+      virtual void build() {
+	Parent::build();
+	Key it;
+	typename Parent::Notifier* nf = Parent::notifier();
+	for (nf->first(it); it != INVALID; nf->next(it)) {
+	  Parent::set(it, 0);
+	}
+      }
+    };
+
+  public:
+
+    /// \brief Constructor.
+    ///
+    /// Constructor for creating out-degree map.
+    explicit OutDegMap(const Digraph& _digraph) : digraph(_digraph), deg(_digraph) {
+      Parent::attach(digraph.notifier(typename _Digraph::Arc()));
+      
+      for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {
+	deg[it] = countOutArcs(digraph, it);
+      }
+    }
+
+    /// Gives back the out-degree of a Node.
+    int operator[](const Key& key) const {
+      return deg[key];
+    }
+
+  protected:
+    
+    typedef typename Digraph::Arc Arc;
+
+    virtual void add(const Arc& arc) {
+      ++deg[digraph.source(arc)];
+    }
+
+    virtual void add(const std::vector<Arc>& arcs) {
+      for (int i = 0; i < int(arcs.size()); ++i) {
+        ++deg[digraph.source(arcs[i])];
+      }
+    }
+
+    virtual void erase(const Arc& arc) {
+      --deg[digraph.source(arc)];
+    }
+
+    virtual void erase(const std::vector<Arc>& arcs) {
+      for (int i = 0; i < int(arcs.size()); ++i) {
+        --deg[digraph.source(arcs[i])];
+      }
+    }
+
+    virtual void build() {
+      for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {
+	deg[it] = countOutArcs(digraph, it);
+      }      
+    }
+
+    virtual void clear() {
+      for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {
+	deg[it] = 0;
+      }
+    }
+  private:
+    
+    const _Digraph& digraph;
+    AutoNodeMap deg;
+  };
+
+
+  ///Dynamic arc look up between given endpoints.
+  
+  ///\ingroup gutils
+  ///Using this class, you can find an arc in a digraph from a given
+  ///source to a given target in amortized time <em>O(log d)</em>,
+  ///where <em>d</em> is the out-degree of the source node.
+  ///
+  ///It is possible to find \e all parallel arcs between two nodes with
+  ///the \c findFirst() and \c findNext() members.
+  ///
+  ///See the \ref ArcLookUp and \ref AllArcLookUp classes if your
+  ///digraph do not changed so frequently.
+  ///
+  ///This class uses a self-adjusting binary search tree, Sleator's
+  ///and Tarjan's Splay tree for guarantee the logarithmic amortized
+  ///time bound for arc lookups. This class also guarantees the
+  ///optimal time bound in a constant factor for any distribution of
+  ///queries.
+  ///
+  ///\param G The type of the underlying digraph.  
+  ///
+  ///\sa ArcLookUp  
+  ///\sa AllArcLookUp  
+  template<class G>
+  class DynArcLookUp 
+    : protected ItemSetTraits<G, typename G::Arc>::ItemNotifier::ObserverBase
+  {
+  public:
+    typedef typename ItemSetTraits<G, typename G::Arc>
+    ::ItemNotifier::ObserverBase Parent;
+
+    GRAPH_TYPEDEFS(typename G);
+    typedef G Digraph;
+
+  protected:
+
+    class AutoNodeMap : public DefaultMap<G, Node, Arc> {
+    public:
+
+      typedef DefaultMap<G, Node, Arc> Parent;
+
+      AutoNodeMap(const G& digraph) : Parent(digraph, INVALID) {}
+      
+      virtual void add(const Node& node) {
+	Parent::add(node);
+	Parent::set(node, INVALID);
+      }
+
+      virtual void add(const std::vector<Node>& nodes) {
+	Parent::add(nodes);
+	for (int i = 0; i < int(nodes.size()); ++i) {
+	  Parent::set(nodes[i], INVALID);
+	}
+      }
+
+      virtual void build() {
+	Parent::build();
+	Node it;
+	typename Parent::Notifier* nf = Parent::notifier();
+	for (nf->first(it); it != INVALID; nf->next(it)) {
+	  Parent::set(it, INVALID);
+	}
+      }
+    };
+
+    const Digraph &_g;
+    AutoNodeMap _head;
+    typename Digraph::template ArcMap<Arc> _parent;
+    typename Digraph::template ArcMap<Arc> _left;
+    typename Digraph::template ArcMap<Arc> _right;
+    
+    class ArcLess {
+      const Digraph &g;
+    public:
+      ArcLess(const Digraph &_g) : g(_g) {}
+      bool operator()(Arc a,Arc b) const 
+      {
+	return g.target(a)<g.target(b);
+      }
+    };
+    
+  public:
+    
+    ///Constructor
+
+    ///Constructor.
+    ///
+    ///It builds up the search database.
+    DynArcLookUp(const Digraph &g) 
+      : _g(g),_head(g),_parent(g),_left(g),_right(g) 
+    { 
+      Parent::attach(_g.notifier(typename Digraph::Arc()));
+      refresh(); 
+    }
+    
+  protected:
+
+    virtual void add(const Arc& arc) {
+      insert(arc);
+    }
+
+    virtual void add(const std::vector<Arc>& arcs) {
+      for (int i = 0; i < int(arcs.size()); ++i) {
+	insert(arcs[i]);
+      }
+    }
+
+    virtual void erase(const Arc& arc) {
+      remove(arc);
+    }
+
+    virtual void erase(const std::vector<Arc>& arcs) {
+      for (int i = 0; i < int(arcs.size()); ++i) {
+	remove(arcs[i]);
+      }     
+    }
+
+    virtual void build() {
+      refresh();
+    }
+
+    virtual void clear() {
+      for(NodeIt n(_g);n!=INVALID;++n) {
+	_head.set(n, INVALID);
+      }
+    }
+
+    void insert(Arc arc) {
+      Node s = _g.source(arc);
+      Node t = _g.target(arc);
+      _left.set(arc, INVALID);
+      _right.set(arc, INVALID);
+      
+      Arc e = _head[s];
+      if (e == INVALID) {
+	_head.set(s, arc);
+	_parent.set(arc, INVALID);
+	return;
+      }
+      while (true) {
+	if (t < _g.target(e)) {
+	  if (_left[e] == INVALID) {
+	    _left.set(e, arc);
+	    _parent.set(arc, e);
+	    splay(arc);
+	    return;
+	  } else {
+	    e = _left[e];
+	  }
+	} else {
+	  if (_right[e] == INVALID) {
+	    _right.set(e, arc);
+	    _parent.set(arc, e);
+	    splay(arc);
+	    return;
+	  } else {
+	    e = _right[e];
+	  }
+	}
+      }
+    }
+
+    void remove(Arc arc) {
+      if (_left[arc] == INVALID) {
+	if (_right[arc] != INVALID) {
+	  _parent.set(_right[arc], _parent[arc]);
+	}
+	if (_parent[arc] != INVALID) {
+	  if (_left[_parent[arc]] == arc) {
+	    _left.set(_parent[arc], _right[arc]);
+	  } else {
+	    _right.set(_parent[arc], _right[arc]);
+	  }
+	} else {
+	  _head.set(_g.source(arc), _right[arc]);
+	}
+      } else if (_right[arc] == INVALID) {
+	_parent.set(_left[arc], _parent[arc]);
+	if (_parent[arc] != INVALID) {
+	  if (_left[_parent[arc]] == arc) {
+	    _left.set(_parent[arc], _left[arc]);
+	  } else {
+	    _right.set(_parent[arc], _left[arc]);
+	  }
+	} else {
+	  _head.set(_g.source(arc), _left[arc]);
+	}
+      } else {
+	Arc e = _left[arc];
+	if (_right[e] != INVALID) {
+	  e = _right[e];	  
+	  while (_right[e] != INVALID) {
+	    e = _right[e];
+	  }
+	  Arc s = _parent[e];
+	  _right.set(_parent[e], _left[e]);
+	  if (_left[e] != INVALID) {
+	    _parent.set(_left[e], _parent[e]);
+	  }
+	  
+	  _left.set(e, _left[arc]);
+	  _parent.set(_left[arc], e);
+	  _right.set(e, _right[arc]);
+	  _parent.set(_right[arc], e);
+
+	  _parent.set(e, _parent[arc]);
+	  if (_parent[arc] != INVALID) {
+	    if (_left[_parent[arc]] == arc) {
+	      _left.set(_parent[arc], e);
+	    } else {
+	      _right.set(_parent[arc], e);
+	    }
+	  }
+	  splay(s);
+	} else {
+	  _right.set(e, _right[arc]);
+	  _parent.set(_right[arc], e);
+
+	  if (_parent[arc] != INVALID) {
+	    if (_left[_parent[arc]] == arc) {
+	      _left.set(_parent[arc], e);
+	    } else {
+	      _right.set(_parent[arc], e);
+	    }
+	  } else {
+	    _head.set(_g.source(arc), e);
+	  }
+	}
+      }
+    }
+
+    Arc refreshRec(std::vector<Arc> &v,int a,int b) 
+    {
+      int m=(a+b)/2;
+      Arc me=v[m];
+      if (a < m) {
+	Arc left = refreshRec(v,a,m-1);
+	_left.set(me, left);
+	_parent.set(left, me);
+      } else {
+	_left.set(me, INVALID);
+      }
+      if (m < b) {
+	Arc right = refreshRec(v,m+1,b);
+	_right.set(me, right);
+	_parent.set(right, me);
+      } else {
+	_right.set(me, INVALID);
+      }
+      return me;
+    }
+
+    void refresh() {
+      for(NodeIt n(_g);n!=INVALID;++n) {
+	std::vector<Arc> v;
+	for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e);
+	if(v.size()) {
+	  std::sort(v.begin(),v.end(),ArcLess(_g));
+	  Arc head = refreshRec(v,0,v.size()-1);
+	  _head.set(n, head);
+	  _parent.set(head, INVALID);
+	}
+	else _head.set(n, INVALID);
+      }
+    }
+
+    void zig(Arc v) {        
+      Arc w = _parent[v];
+      _parent.set(v, _parent[w]);
+      _parent.set(w, v);
+      _left.set(w, _right[v]);
+      _right.set(v, w);
+      if (_parent[v] != INVALID) {
+	if (_right[_parent[v]] == w) {
+	  _right.set(_parent[v], v);
+	} else {
+	  _left.set(_parent[v], v);
+	}
+      }
+      if (_left[w] != INVALID){
+	_parent.set(_left[w], w);
+      }
+    }
+
+    void zag(Arc v) {        
+      Arc w = _parent[v];
+      _parent.set(v, _parent[w]);
+      _parent.set(w, v);
+      _right.set(w, _left[v]);
+      _left.set(v, w);
+      if (_parent[v] != INVALID){
+	if (_left[_parent[v]] == w) {
+	  _left.set(_parent[v], v);
+	} else {
+	  _right.set(_parent[v], v);
+	}
+      }
+      if (_right[w] != INVALID){
+	_parent.set(_right[w], w);
+      }
+    }
+
+    void splay(Arc v) {
+      while (_parent[v] != INVALID) {
+	if (v == _left[_parent[v]]) {
+	  if (_parent[_parent[v]] == INVALID) {
+	    zig(v);
+	  } else {
+	    if (_parent[v] == _left[_parent[_parent[v]]]) {
+	      zig(_parent[v]);
+	      zig(v);
+	    } else {
+	      zig(v);
+	      zag(v);
+	    }
+	  }
+	} else {
+	  if (_parent[_parent[v]] == INVALID) {
+	    zag(v);
+	  } else {
+	    if (_parent[v] == _left[_parent[_parent[v]]]) {
+	      zag(v);
+	      zig(v);
+	    } else {
+	      zag(_parent[v]);
+	      zag(v);
+	    }
+	  }
+	}
+      }
+      _head[_g.source(v)] = v;
+    }
+
+
+  public:
+    
+    ///Find an arc between two nodes.
+    
+    ///Find an arc between two nodes in time <em>O(</em>log<em>d)</em>, where
+    /// <em>d</em> is the number of outgoing arcs of \c s.
+    ///\param s The source node
+    ///\param t The target node
+    ///\return An arc from \c s to \c t if there exists,
+    ///\ref INVALID otherwise.
+    Arc operator()(Node s, Node t) const
+    {
+      Arc e = _head[s];
+      while (true) {
+	if (_g.target(e) == t) {
+	  const_cast<DynArcLookUp&>(*this).splay(e);
+	  return e;
+	} else if (t < _g.target(e)) {
+	  if (_left[e] == INVALID) {
+	    const_cast<DynArcLookUp&>(*this).splay(e);
+	    return INVALID;
+	  } else {
+	    e = _left[e];
+	  }
+	} else  {
+	  if (_right[e] == INVALID) {
+	    const_cast<DynArcLookUp&>(*this).splay(e);
+	    return INVALID;
+	  } else {
+	    e = _right[e];
+	  }
+	}
+      }
+    }
+
+    ///Find the first arc between two nodes.
+    
+    ///Find the first arc between two nodes in time
+    /// <em>O(</em>log<em>d)</em>, where <em>d</em> is the number of
+    /// outgoing arcs of \c s.  
+    ///\param s The source node 
+    ///\param t The target node
+    ///\return An arc from \c s to \c t if there exists, \ref INVALID
+    /// otherwise.
+    Arc findFirst(Node s, Node t) const
+    {
+      Arc e = _head[s];
+      Arc r = INVALID;
+      while (true) {
+	if (_g.target(e) < t) {
+	  if (_right[e] == INVALID) {
+	    const_cast<DynArcLookUp&>(*this).splay(e);
+	    return r;
+	  } else {
+	    e = _right[e];
+	  }
+	} else {
+	  if (_g.target(e) == t) {
+	    r = e;
+	  }
+	  if (_left[e] == INVALID) {
+	    const_cast<DynArcLookUp&>(*this).splay(e);
+	    return r;
+	  } else {
+	    e = _left[e];
+	  }
+	}
+      }
+    }
+
+    ///Find the next arc between two nodes.
+    
+    ///Find the next arc between two nodes in time
+    /// <em>O(</em>log<em>d)</em>, where <em>d</em> is the number of
+    /// outgoing arcs of \c s.  
+    ///\param s The source node 
+    ///\param t The target node
+    ///\return An arc from \c s to \c t if there exists, \ref INVALID
+    /// otherwise.
+
+    ///\note If \c e is not the result of the previous \c findFirst()
+    ///operation then the amorized time bound can not be guaranteed.
+#ifdef DOXYGEN
+    Arc findNext(Node s, Node t, Arc e) const
+#else
+    Arc findNext(Node, Node t, Arc e) const
+#endif
+    {
+      if (_right[e] != INVALID) {
+	e = _right[e];
+	while (_left[e] != INVALID) {
+	  e = _left[e];
+	}
+	const_cast<DynArcLookUp&>(*this).splay(e);
+      } else {
+	while (_parent[e] != INVALID && _right[_parent[e]] ==  e) {
+	  e = _parent[e];
+	}
+	if (_parent[e] == INVALID) {
+	  return INVALID;
+	} else {
+	  e = _parent[e];
+	  const_cast<DynArcLookUp&>(*this).splay(e);
+	}
+      }
+      if (_g.target(e) == t) return e;
+      else return INVALID;    
+    }
+
+  };
+
+  ///Fast arc look up between given endpoints.
+  
+  ///\ingroup gutils
+  ///Using this class, you can find an arc in a digraph from a given
+  ///source to a given target in time <em>O(log d)</em>,
+  ///where <em>d</em> is the out-degree of the source node.
+  ///
+  ///It is not possible to find \e all parallel arcs between two nodes.
+  ///Use \ref AllArcLookUp for this purpose.
+  ///
+  ///\warning This class is static, so you should refresh() (or at least
+  ///refresh(Node)) this data structure
+  ///whenever the digraph changes. This is a time consuming (superlinearly
+  ///proportional (<em>O(m</em>log<em>m)</em>) to the number of arcs).
+  ///
+  ///\param G The type of the underlying digraph.
+  ///
+  ///\sa DynArcLookUp
+  ///\sa AllArcLookUp  
+  template<class G>
+  class ArcLookUp 
+  {
+  public:
+    GRAPH_TYPEDEFS(typename G);
+    typedef G Digraph;
+
+  protected:
+    const Digraph &_g;
+    typename Digraph::template NodeMap<Arc> _head;
+    typename Digraph::template ArcMap<Arc> _left;
+    typename Digraph::template ArcMap<Arc> _right;
+    
+    class ArcLess {
+      const Digraph &g;
+    public:
+      ArcLess(const Digraph &_g) : g(_g) {}
+      bool operator()(Arc a,Arc b) const 
+      {
+	return g.target(a)<g.target(b);
+      }
+    };
+    
+  public:
+    
+    ///Constructor
+
+    ///Constructor.
+    ///
+    ///It builds up the search database, which remains valid until the digraph
+    ///changes.
+    ArcLookUp(const Digraph &g) :_g(g),_head(g),_left(g),_right(g) {refresh();}
+    
+  private:
+    Arc refreshRec(std::vector<Arc> &v,int a,int b) 
+    {
+      int m=(a+b)/2;
+      Arc me=v[m];
+      _left[me] = a<m?refreshRec(v,a,m-1):INVALID;
+      _right[me] = m<b?refreshRec(v,m+1,b):INVALID;
+      return me;
+    }
+  public:
+    ///Refresh the data structure at a node.
+
+    ///Build up the search database of node \c n.
+    ///
+    ///It runs in time <em>O(d</em>log<em>d)</em>, where <em>d</em> is
+    ///the number of the outgoing arcs of \c n.
+    void refresh(Node n) 
+    {
+      std::vector<Arc> v;
+      for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e);
+      if(v.size()) {
+	std::sort(v.begin(),v.end(),ArcLess(_g));
+	_head[n]=refreshRec(v,0,v.size()-1);
+      }
+      else _head[n]=INVALID;
+    }
+    ///Refresh the full data structure.
+
+    ///Build up the full search database. In fact, it simply calls
+    ///\ref refresh(Node) "refresh(n)" for each node \c n.
+    ///
+    ///It runs in time <em>O(m</em>log<em>D)</em>, where <em>m</em> is
+    ///the number of the arcs of \c n and <em>D</em> is the maximum
+    ///out-degree of the digraph.
+
+    void refresh() 
+    {
+      for(NodeIt n(_g);n!=INVALID;++n) refresh(n);
+    }
+    
+    ///Find an arc between two nodes.
+    
+    ///Find an arc between two nodes in time <em>O(</em>log<em>d)</em>, where
+    /// <em>d</em> is the number of outgoing arcs of \c s.
+    ///\param s The source node
+    ///\param t The target node
+    ///\return An arc from \c s to \c t if there exists,
+    ///\ref INVALID otherwise.
+    ///
+    ///\warning If you change the digraph, refresh() must be called before using
+    ///this operator. If you change the outgoing arcs of
+    ///a single node \c n, then
+    ///\ref refresh(Node) "refresh(n)" is enough.
+    ///
+    Arc operator()(Node s, Node t) const
+    {
+      Arc e;
+      for(e=_head[s];
+	  e!=INVALID&&_g.target(e)!=t;
+	  e = t < _g.target(e)?_left[e]:_right[e]) ;
+      return e;
+    }
+
+  };
+
+  ///Fast look up of all arcs between given endpoints.
+  
+  ///\ingroup gutils
+  ///This class is the same as \ref ArcLookUp, with the addition
+  ///that it makes it possible to find all arcs between given endpoints.
+  ///
+  ///\warning This class is static, so you should refresh() (or at least
+  ///refresh(Node)) this data structure
+  ///whenever the digraph changes. This is a time consuming (superlinearly
+  ///proportional (<em>O(m</em>log<em>m)</em>) to the number of arcs).
+  ///
+  ///\param G The type of the underlying digraph.
+  ///
+  ///\sa DynArcLookUp
+  ///\sa ArcLookUp  
+  template<class G>
+  class AllArcLookUp : public ArcLookUp<G>
+  {
+    using ArcLookUp<G>::_g;
+    using ArcLookUp<G>::_right;
+    using ArcLookUp<G>::_left;
+    using ArcLookUp<G>::_head;
+
+    GRAPH_TYPEDEFS(typename G);
+    typedef G Digraph;
+    
+    typename Digraph::template ArcMap<Arc> _next;
+    
+    Arc refreshNext(Arc head,Arc next=INVALID)
+    {
+      if(head==INVALID) return next;
+      else {
+	next=refreshNext(_right[head],next);
+// 	_next[head]=next;
+	_next[head]=( next!=INVALID && _g.target(next)==_g.target(head))
+	  ? next : INVALID;
+	return refreshNext(_left[head],head);
+      }
+    }
+    
+    void refreshNext()
+    {
+      for(NodeIt n(_g);n!=INVALID;++n) refreshNext(_head[n]);
+    }
+    
+  public:
+    ///Constructor
+
+    ///Constructor.
+    ///
+    ///It builds up the search database, which remains valid until the digraph
+    ///changes.
+    AllArcLookUp(const Digraph &g) : ArcLookUp<G>(g), _next(g) {refreshNext();}
+
+    ///Refresh the data structure at a node.
+
+    ///Build up the search database of node \c n.
+    ///
+    ///It runs in time <em>O(d</em>log<em>d)</em>, where <em>d</em> is
+    ///the number of the outgoing arcs of \c n.
+    
+    void refresh(Node n) 
+    {
+      ArcLookUp<G>::refresh(n);
+      refreshNext(_head[n]);
+    }
+    
+    ///Refresh the full data structure.
+
+    ///Build up the full search database. In fact, it simply calls
+    ///\ref refresh(Node) "refresh(n)" for each node \c n.
+    ///
+    ///It runs in time <em>O(m</em>log<em>D)</em>, where <em>m</em> is
+    ///the number of the arcs of \c n and <em>D</em> is the maximum
+    ///out-degree of the digraph.
+
+    void refresh() 
+    {
+      for(NodeIt n(_g);n!=INVALID;++n) refresh(_head[n]);
+    }
+    
+    ///Find an arc between two nodes.
+    
+    ///Find an arc between two nodes.
+    ///\param s The source node
+    ///\param t The target node
+    ///\param prev The previous arc between \c s and \c t. It it is INVALID or
+    ///not given, the operator finds the first appropriate arc.
+    ///\return An arc from \c s to \c t after \c prev or
+    ///\ref INVALID if there is no more.
+    ///
+    ///For example, you can count the number of arcs from \c u to \c v in the
+    ///following way.
+    ///\code
+    ///AllArcLookUp<ListDigraph> ae(g);
+    ///...
+    ///int n=0;
+    ///for(Arc e=ae(u,v);e!=INVALID;e=ae(u,v,e)) n++;
+    ///\endcode
+    ///
+    ///Finding the first arc take <em>O(</em>log<em>d)</em> time, where
+    /// <em>d</em> is the number of outgoing arcs of \c s. Then, the
+    ///consecutive arcs are found in constant time.
+    ///
+    ///\warning If you change the digraph, refresh() must be called before using
+    ///this operator. If you change the outgoing arcs of
+    ///a single node \c n, then
+    ///\ref refresh(Node) "refresh(n)" is enough.
+    ///
+#ifdef DOXYGEN
+    Arc operator()(Node s, Node t, Arc prev=INVALID) const {}
+#else
+    using ArcLookUp<G>::operator() ;
+    Arc operator()(Node s, Node t, Arc prev) const
+    {
+      return prev==INVALID?(*this)(s,t):_next[prev];
+    }
+#endif
+      
+  };
+
+  /// @}
+
+} //END OF NAMESPACE LEMON
+
+#endif
Index: lemon/kruskal.h
===================================================================
--- lemon/kruskal.h	(revision 103)
+++ 	(revision )
@@ -1,319 +1,0 @@
-/* -*- C++ -*-
- *
- * This file is a part of LEMON, a generic C++ optimization library
- *
- * Copyright (C) 2003-2008
- * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
- * (Egervary Research Group on Combinatorial Optimization, EGRES).
- *
- * Permission to use, modify and distribute this software is granted
- * provided that this copyright notice appears in all copies. For
- * precise terms see the accompanying LICENSE file.
- *
- * This software is provided "AS IS" with no warranty of any kind,
- * express or implied, and with no claim as to its suitability for any
- * purpose.
- *
- */
-
-#ifndef LEMON_KRUSKAL_H
-#define LEMON_KRUSKAL_H
-
-#include <algorithm>
-#include <vector>
-#include <lemon/unionfind.h>
-// #include <lemon/graph_utils.h>
-#include <lemon/maps.h>
-
-// #include <lemon/radix_sort.h>
-
-#include <lemon/bits/utility.h>
-#include <lemon/bits/traits.h>
-
-///\ingroup spantree
-///\file
-///\brief Kruskal's algorithm to compute a minimum cost tree
-///
-///Kruskal's algorithm to compute a minimum cost tree.
-///
-
-namespace lemon {
-
-  namespace _kruskal_bits {
-
-    // Kruskal for directed graphs.
-
-    template <typename Digraph, typename In, typename Out>
-    typename disable_if<lemon::UndirectedTagIndicator<Digraph>,
-		       typename In::value_type::second_type >::type
-    kruskal(const Digraph& digraph, const In& in, Out& out,dummy<0> = 0) {
-      typedef typename In::value_type::second_type Value;
-      typedef typename Digraph::template NodeMap<int> IndexMap;
-      typedef typename Digraph::Node Node;
-      
-      IndexMap index(digraph);
-      UnionFind<IndexMap> uf(index);
-      for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) {
-        uf.insert(it);
-      }
-      
-      Value tree_value = 0;
-      for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) {
-        if (uf.join(digraph.target(it->first),digraph.source(it->first))) {
-          out.set(it->first, true);
-          tree_value += it->second;
-        }
-        else {
-          out.set(it->first, false);
-        }
-      }
-      return tree_value;
-    }
-
-    // Kruskal for undirected graphs.
-
-    template <typename Graph, typename In, typename Out>
-    typename enable_if<lemon::UndirectedTagIndicator<Graph>,
-		       typename In::value_type::second_type >::type
-    kruskal(const Graph& graph, const In& in, Out& out,dummy<1> = 1) {
-      typedef typename In::value_type::second_type Value;
-      typedef typename Graph::template NodeMap<int> IndexMap;
-      typedef typename Graph::Node Node;
-      
-      IndexMap index(graph);
-      UnionFind<IndexMap> uf(index);
-      for (typename Graph::NodeIt it(graph); it != INVALID; ++it) {
-        uf.insert(it);
-      }
-      
-      Value tree_value = 0;
-      for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) {
-        if (uf.join(graph.u(it->first),graph.v(it->first))) {
-          out.set(it->first, true);
-          tree_value += it->second;
-        }
-        else {
-          out.set(it->first, false);
-        }
-      }
-      return tree_value;
-    }
-
-
-    template <typename Sequence>
-    struct PairComp {
-      typedef typename Sequence::value_type Value;
-      bool operator()(const Value& left, const Value& right) {
-	return left.second < right.second;
-      }
-    };
-
-    template <typename In, typename Enable = void>
-    struct SequenceInputIndicator {
-      static const bool value = false;
-    };
-
-    template <typename In>
-    struct SequenceInputIndicator<In, 
-      typename exists<typename In::value_type::first_type>::type> {
-      static const bool value = true;
-    };
-
-    template <typename In, typename Enable = void>
-    struct MapInputIndicator {
-      static const bool value = false;
-    };
-
-    template <typename In>
-    struct MapInputIndicator<In, 
-      typename exists<typename In::Value>::type> {
-      static const bool value = true;
-    };
-
-    template <typename In, typename Enable = void>
-    struct SequenceOutputIndicator {
-      static const bool value = false;
-    };
- 
-    template <typename Out>
-    struct SequenceOutputIndicator<Out, 
-      typename exists<typename Out::value_type>::type> {
-      static const bool value = true;
-    };
-
-    template <typename Out, typename Enable = void>
-    struct MapOutputIndicator {
-      static const bool value = false;
-    };
-
-    template <typename Out>
-    struct MapOutputIndicator<Out, 
-      typename exists<typename Out::Value>::type> {
-      static const bool value = true;
-    };
-
-    template <typename In, typename InEnable = void>
-    struct KruskalValueSelector {};
-
-    template <typename In>
-    struct KruskalValueSelector<In,
-      typename enable_if<SequenceInputIndicator<In>, void>::type> 
-    {
-      typedef typename In::value_type::second_type Value;
-    };    
-
-    template <typename In>
-    struct KruskalValueSelector<In,
-      typename enable_if<MapInputIndicator<In>, void>::type> 
-    {
-      typedef typename In::Value Value;
-    };    
-    
-    template <typename Graph, typename In, typename Out,
-              typename InEnable = void>
-    struct KruskalInputSelector {};
-
-    template <typename Graph, typename In, typename Out,
-              typename InEnable = void>
-    struct KruskalOutputSelector {};
-    
-    template <typename Graph, typename In, typename Out>
-    struct KruskalInputSelector<Graph, In, Out,
-      typename enable_if<SequenceInputIndicator<In>, void>::type > 
-    {
-      typedef typename In::value_type::second_type Value;
-
-      static Value kruskal(const Graph& graph, const In& in, Out& out) {
-        return KruskalOutputSelector<Graph, In, Out>::
-          kruskal(graph, in, out);
-      }
-
-    };
-
-    template <typename Graph, typename In, typename Out>
-    struct KruskalInputSelector<Graph, In, Out,
-      typename enable_if<MapInputIndicator<In>, void>::type > 
-    {
-      typedef typename In::Value Value;
-      static Value kruskal(const Graph& graph, const In& in, Out& out) {
-        typedef typename In::Key MapArc;
-        typedef typename In::Value Value;
-        typedef typename ItemSetTraits<Graph, MapArc>::ItemIt MapArcIt;
-        typedef std::vector<std::pair<MapArc, Value> > Sequence;
-        Sequence seq;
-        
-        for (MapArcIt it(graph); it != INVALID; ++it) {
-          seq.push_back(std::make_pair(it, in[it]));
-        }
-
-        std::sort(seq.begin(), seq.end(), PairComp<Sequence>());
-        return KruskalOutputSelector<Graph, Sequence, Out>::
-          kruskal(graph, seq, out);
-      }
-    };
-
-    template <typename Graph, typename In, typename Out>
-    struct KruskalOutputSelector<Graph, In, Out,
-      typename enable_if<SequenceOutputIndicator<Out>, void>::type > 
-    {
-      typedef typename In::value_type::second_type Value;
-
-      static Value kruskal(const Graph& graph, const In& in, Out& out) {
-        typedef StoreBoolMap<Out> Map;
-        Map map(out);
-        return _kruskal_bits::kruskal(graph, in, map);
-      }
-
-    };
-
-    template <typename Graph, typename In, typename Out>
-    struct KruskalOutputSelector<Graph, In, Out,
-      typename enable_if<MapOutputIndicator<Out>, void>::type > 
-    {
-      typedef typename In::value_type::second_type Value;
-
-      static Value kruskal(const Graph& graph, const In& in, Out& out) {
-        return _kruskal_bits::kruskal(graph, in, out);
-      }
-    };
-
-  }
-
-  /// \ingroup spantree
-  ///
-  /// \brief Kruskal's algorithm to find a minimum cost tree of a graph.
-  ///
-  /// This function runs Kruskal's algorithm to find a minimum cost tree.
-  /// Due to some C++ hacking, it accepts various input and output types.
-  ///
-  /// \param g The graph the algorithm runs on.
-  /// It can be either \ref concepts::Digraph "directed" or 
-  /// \ref concepts::Graph "undirected".
-  /// If the graph is directed, the algorithm consider it to be 
-  /// undirected by disregarding the direction of the arcs.
-  ///
-  /// \param in This object is used to describe the arc costs. It can be one
-  /// of the following choices.
-  /// - An STL compatible 'Forward Container' with
-  /// <tt>std::pair<GR::Edge,X></tt> or
-  /// <tt>std::pair<GR::Arc,X></tt> as its <tt>value_type</tt>, where
-  /// \c X is the type of the costs. The pairs indicates the arcs
-  /// along with the assigned cost. <em>They must be in a
-  /// cost-ascending order.</em>
-  /// - Any readable Arc map. The values of the map indicate the arc costs.
-  ///
-  /// \retval out Here we also have a choise.
-  /// - It can be a writable \c bool arc map.  After running the
-  /// algorithm this will contain the found minimum cost spanning
-  /// tree: the value of an arc will be set to \c true if it belongs
-  /// to the tree, otherwise it will be set to \c false. The value of
-  /// each arc will be set exactly once.
-  /// - It can also be an iteraror of an STL Container with
-  /// <tt>GR::Edge</tt> or <tt>GR::Arc</tt> as its
-  /// <tt>value_type</tt>.  The algorithm copies the elements of the
-  /// found tree into this sequence.  For example, if we know that the
-  /// spanning tree of the graph \c g has say 53 arcs, then we can
-  /// put its arcs into an STL vector \c tree with a code like this.
-  ///\code
-  /// std::vector<Arc> tree(53);
-  /// kruskal(g,cost,tree.begin());
-  ///\endcode
-  /// Or if we don't know in advance the size of the tree, we can
-  /// write this.  
-  ///\code std::vector<Arc> tree;
-  /// kruskal(g,cost,std::back_inserter(tree)); 
-  ///\endcode
-  ///
-  /// \return The total cost of the found tree.
-  ///
-  /// \warning If kruskal runs on an be consistent of using the same
-  /// Arc type for input and output.
-  ///
-
-#ifdef DOXYGEN
-  template <class Graph, class In, class Out>
-  Value kruskal(GR const& g, const In& in, Out& out)
-#else 
-  template <class Graph, class In, class Out>
-  inline typename _kruskal_bits::KruskalValueSelector<In>::Value 
-  kruskal(const Graph& graph, const In& in, Out& out) 
-#endif
-  {
-    return _kruskal_bits::KruskalInputSelector<Graph, In, Out>::
-      kruskal(graph, in, out);
-  }
-
- 
-  
-
-  template <class Graph, class In, class Out>
-  inline typename _kruskal_bits::KruskalValueSelector<In>::Value
-  kruskal(const Graph& graph, const In& in, const Out& out)
-  {
-    return _kruskal_bits::KruskalInputSelector<Graph, In, const Out>::
-      kruskal(graph, in, out);
-  }  
-
-} //namespace lemon
-
-#endif //LEMON_KRUSKAL_H
Index: lemon/maps.h
===================================================================
--- lemon/maps.h	(revision 54)
+++ lemon/maps.h	(revision 104)
@@ -25,10 +25,10 @@
 
 #include <lemon/bits/utility.h>
-// #include <lemon/bits/traits.h>
+#include <lemon/bits/traits.h>
 
 ///\file
 ///\ingroup maps
 ///\brief Miscellaneous property maps
-///
+
 #include <map>
 
@@ -40,39 +40,44 @@
   /// Base class of maps.
 
-  /// Base class of maps.
-  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
-  template<typename K, typename T>
+  /// Base class of maps. It provides the necessary type definitions
+  /// required by the map %concepts.
+  template<typename K, typename V>
   class MapBase {
   public:
-    /// The key type of the map.
+    /// \biref The key type of the map.
     typedef K Key;
-    /// The value type of the map. (The type of objects associated with the keys).
-    typedef T Value;
-  };
+    /// \brief The value type of the map.
+    /// (The type of objects associated with the keys).
+    typedef V Value;
+  };
+
 
   /// Null map. (a.k.a. DoNothingMap)
 
   /// This map can be used if you have to provide a map only for
-  /// its type definitions, or if you have to provide a writable map, 
-  /// but data written to it is not required (i.e. it will be sent to 
+  /// its type definitions, or if you have to provide a writable map,
+  /// but data written to it is not required (i.e. it will be sent to
   /// <tt>/dev/null</tt>).
-  template<typename K, typename T>
-  class NullMap : public MapBase<K, T> {
-  public:
-    typedef MapBase<K, T> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-    
+  /// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
+  ///
+  /// \sa ConstMap
+  template<typename K, typename V>
+  class NullMap : public MapBase<K, V> {
+  public:
+    typedef MapBase<K, V> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
     /// Gives back a default constructed element.
-    T operator[](const K&) const { return T(); }
+    Value operator[](const Key&) const { return Value(); }
     /// Absorbs the value.
-    void set(const K&, const T&) {}
-  };
-
-  ///Returns a \c NullMap class
-
-  ///This function just returns a \c NullMap class.
-  ///\relates NullMap
-  template <typename K, typename V> 
+    void set(const Key&, const Value&) {}
+  };
+
+  /// Returns a \ref NullMap class
+
+  /// This function just returns a \ref NullMap class.
+  /// \relates NullMap
+  template <typename K, typename V>
   NullMap<K, V> nullMap() {
     return NullMap<K, V>();
@@ -82,14 +87,22 @@
   /// Constant map.
 
-  /// This is a \ref concepts::ReadMap "readable" map which assigns a 
-  /// specified value to each key.
-  /// In other aspects it is equivalent to \c NullMap.
-  template<typename K, typename T>
-  class ConstMap : public MapBase<K, T> {
+  /// This \ref concepts::ReadMap "readable map" assigns a specified
+  /// value to each key.
+  ///
+  /// In other aspects it is equivalent to \ref NullMap.
+  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
+  /// concept, but it absorbs the data written to it.
+  ///
+  /// The simplest way of using this map is through the constMap()
+  /// function.
+  ///
+  /// \sa NullMap
+  /// \sa IdentityMap
+  template<typename K, typename V>
+  class ConstMap : public MapBase<K, V> {
   private:
-    T v;
-  public:
-
-    typedef MapBase<K, T> Parent;
+    V _value;
+  public:
+    typedef MapBase<K, V> Parent;
     typedef typename Parent::Key Key;
     typedef typename Parent::Value Value;
@@ -98,31 +111,33 @@
 
     /// Default constructor.
-    /// The value of the map will be uninitialized. 
-    /// (More exactly it will be default constructed.)
+    /// The value of the map will be default constructed.
     ConstMap() {}
-    
+
     /// Constructor with specified initial value
 
     /// Constructor with specified initial value.
-    /// \param _v is the initial value of the map.
-    ConstMap(const T &_v) : v(_v) {}
-    
-    ///\e
-    T operator[](const K&) const { return v; }
-
-    ///\e
-    void setAll(const T &t) {
-      v = t;
-    }    
-
-    template<typename T1>
-    ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
-  };
-
-  ///Returns a \c ConstMap class
-
-  ///This function just returns a \c ConstMap class.
-  ///\relates ConstMap
-  template<typename K, typename V> 
+    /// \param v is the initial value of the map.
+    ConstMap(const Value &v) : _value(v) {}
+
+    /// Gives back the specified value.
+    Value operator[](const Key&) const { return _value; }
+
+    /// Absorbs the value.
+    void set(const Key&, const Value&) {}
+
+    /// Sets the value that is assigned to each key.
+    void setAll(const Value &v) {
+      _value = v;
+    }
+
+    template<typename V1>
+    ConstMap(const ConstMap<K, V1> &, const Value &v) : _value(v) {}
+  };
+
+  /// Returns a \ref ConstMap class
+
+  /// This function just returns a \ref ConstMap class.
+  /// \relates ConstMap
+  template<typename K, typename V>
   inline ConstMap<K, V> constMap(const V &v) {
     return ConstMap<K, V>(v);
@@ -131,11 +146,20 @@
 
   template<typename T, T v>
-  struct Const { };
+  struct Const {};
 
   /// Constant map with inlined constant value.
 
-  /// This is a \ref concepts::ReadMap "readable" map which assigns a 
-  /// specified value to each key.
-  /// In other aspects it is equivalent to \c NullMap.
+  /// This \ref concepts::ReadMap "readable map" assigns a specified
+  /// value to each key.
+  ///
+  /// In other aspects it is equivalent to \ref NullMap.
+  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
+  /// concept, but it absorbs the data written to it.
+  ///
+  /// The simplest way of using this map is through the constMap()
+  /// function.
+  ///
+  /// \sa NullMap
+  /// \sa IdentityMap
   template<typename K, typename V, V v>
   class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
@@ -145,67 +169,228 @@
     typedef typename Parent::Value Value;
 
-    ConstMap() { }
-    ///\e
-    V operator[](const K&) const { return v; }
-    ///\e
-    void set(const K&, const V&) { }
-  };
-
-  ///Returns a \c ConstMap class with inlined value
-
-  ///This function just returns a \c ConstMap class with inlined value.
-  ///\relates ConstMap
-  template<typename K, typename V, V v> 
+    /// Constructor.
+    ConstMap() {}
+
+    /// Gives back the specified value.
+    Value operator[](const Key&) const { return v; }
+
+    /// Absorbs the value.
+    void set(const Key&, const Value&) {}
+  };
+
+  /// Returns a \ref ConstMap class with inlined constant value
+
+  /// This function just returns a \ref ConstMap class with inlined
+  /// constant value.
+  /// \relates ConstMap
+  template<typename K, typename V, V v>
   inline ConstMap<K, Const<V, v> > constMap() {
     return ConstMap<K, Const<V, v> >();
   }
 
-  ///Map based on \c std::map
-
-  ///This is essentially a wrapper for \c std::map with addition that
-  ///you can specify a default value different from \c Value().
-  ///It meets the \ref concepts::ReferenceMap "ReferenceMap" concept.
-  template <typename K, typename T, typename Compare = std::less<K> >
-  class StdMap : public MapBase<K, T> {
-    template <typename K1, typename T1, typename C1>
-    friend class StdMap;
-  public:
-
-    typedef MapBase<K, T> Parent;
-    ///Key type
-    typedef typename Parent::Key Key;
-    ///Value type
-    typedef typename Parent::Value Value;
-    ///Reference Type
-    typedef T& Reference;
-    ///Const reference type
-    typedef const T& ConstReference;
+
+  /// Identity map.
+
+  /// This \ref concepts::ReadMap "read-only map" gives back the given
+  /// key as value without any modification.
+  ///
+  /// \sa ConstMap
+  template <typename T>
+  class IdentityMap : public MapBase<T, T> {
+  public:
+    typedef MapBase<T, T> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Gives back the given value without any modification.
+    Value operator[](const Key &k) const {
+      return k;
+    }
+  };
+
+  /// Returns an \ref IdentityMap class
+
+  /// This function just returns an \ref IdentityMap class.
+  /// \relates IdentityMap
+  template<typename T>
+  inline IdentityMap<T> identityMap() {
+    return IdentityMap<T>();
+  }
+
+
+  /// \brief Map for storing values for integer keys from the range
+  /// <tt>[0..size-1]</tt>.
+  ///
+  /// This map is essentially a wrapper for \c std::vector. It assigns
+  /// values to integer keys from the range <tt>[0..size-1]</tt>.
+  /// It can be used with some data structures, for example
+  /// \ref UnionFind, \ref BinHeap, when the used items are small
+  /// integers. This map conforms the \ref concepts::ReferenceMap
+  /// "ReferenceMap" concept.
+  ///
+  /// The simplest way of using this map is through the rangeMap()
+  /// function.
+  template <typename V>
+  class RangeMap : public MapBase<int, V> {
+    template <typename V1>
+    friend class RangeMap;
+  private:
+
+    typedef std::vector<V> Vector;
+    Vector _vector;
+
+  public:
+
+    typedef MapBase<int, V> Parent;
+    /// Key type
+    typedef typename Parent::Key Key;
+    /// Value type
+    typedef typename Parent::Value Value;
+    /// Reference type
+    typedef typename Vector::reference Reference;
+    /// Const reference type
+    typedef typename Vector::const_reference ConstReference;
 
     typedef True ReferenceMapTag;
 
+  public:
+
+    /// Constructor with specified default value.
+    RangeMap(int size = 0, const Value &value = Value())
+      : _vector(size, value) {}
+
+    /// Constructs the map from an appropriate \c std::vector.
+    template <typename V1>
+    RangeMap(const std::vector<V1>& vector)
+      : _vector(vector.begin(), vector.end()) {}
+
+    /// Constructs the map from another \ref RangeMap.
+    template <typename V1>
+    RangeMap(const RangeMap<V1> &c)
+      : _vector(c._vector.begin(), c._vector.end()) {}
+
+    /// Returns the size of the map.
+    int size() {
+      return _vector.size();
+    }
+
+    /// Resizes the map.
+
+    /// Resizes the underlying \c std::vector container, so changes the
+    /// keyset of the map.
+    /// \param size The new size of the map. The new keyset will be the
+    /// range <tt>[0..size-1]</tt>.
+    /// \param value The default value to assign to the new keys.
+    void resize(int size, const Value &value = Value()) {
+      _vector.resize(size, value);
+    }
+
   private:
-    
-    typedef std::map<K, T, Compare> Map;
+
+    RangeMap& operator=(const RangeMap&);
+
+  public:
+
+    ///\e
+    Reference operator[](const Key &k) {
+      return _vector[k];
+    }
+
+    ///\e
+    ConstReference operator[](const Key &k) const {
+      return _vector[k];
+    }
+
+    ///\e
+    void set(const Key &k, const Value &v) {
+      _vector[k] = v;
+    }
+  };
+
+  /// Returns a \ref RangeMap class
+
+  /// This function just returns a \ref RangeMap class.
+  /// \relates RangeMap
+  template<typename V>
+  inline RangeMap<V> rangeMap(int size = 0, const V &value = V()) {
+    return RangeMap<V>(size, value);
+  }
+
+  /// \brief Returns a \ref RangeMap class created from an appropriate
+  /// \c std::vector
+
+  /// This function just returns a \ref RangeMap class created from an
+  /// appropriate \c std::vector.
+  /// \relates RangeMap
+  template<typename V>
+  inline RangeMap<V> rangeMap(const std::vector<V> &vector) {
+    return RangeMap<V>(vector);
+  }
+
+
+  /// Map type based on \c std::map
+
+  /// This map is essentially a wrapper for \c std::map with addition
+  /// that you can specify a default value for the keys that are not
+  /// stored actually. This value can be different from the default
+  /// contructed value (i.e. \c %Value()).
+  /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap"
+  /// concept.
+  ///
+  /// This map is useful if a default value should be assigned to most of
+  /// the keys and different values should be assigned only to a few
+  /// keys (i.e. the map is "sparse").
+  /// The name of this type also refers to this important usage.
+  ///
+  /// Apart form that this map can be used in many other cases since it
+  /// is based on \c std::map, which is a general associative container.
+  /// However keep in mind that it is usually not as efficient as other
+  /// maps.
+  ///
+  /// The simplest way of using this map is through the sparseMap()
+  /// function.
+  template <typename K, typename V, typename Compare = std::less<K> >
+  class SparseMap : public MapBase<K, V> {
+    template <typename K1, typename V1, typename C1>
+    friend class SparseMap;
+  public:
+
+    typedef MapBase<K, V> Parent;
+    /// Key type
+    typedef typename Parent::Key Key;
+    /// Value type
+    typedef typename Parent::Value Value;
+    /// Reference type
+    typedef Value& Reference;
+    /// Const reference type
+    typedef const Value& ConstReference;
+
+    typedef True ReferenceMapTag;
+
+  private:
+
+    typedef std::map<K, V, Compare> Map;
+    Map _map;
     Value _value;
-    Map _map;
-
-  public:
-
-    /// Constructor with specified default value
-    StdMap(const T& value = T()) : _value(value) {}
-    /// \brief Constructs the map from an appropriate \c std::map, and 
+
+  public:
+
+    /// \brief Constructor with specified default value.
+    SparseMap(const Value &value = Value()) : _value(value) {}
+    /// \brief Constructs the map from an appropriate \c std::map, and
     /// explicitly specifies a default value.
-    template <typename T1, typename Comp1>
-    StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) 
+    template <typename V1, typename Comp1>
+    SparseMap(const std::map<Key, V1, Comp1> &map,
+              const Value &value = Value())
       : _map(map.begin(), map.end()), _value(value) {}
-    
-    /// \brief Constructs a map from an other \ref StdMap.
-    template<typename T1, typename Comp1>
-    StdMap(const StdMap<Key, T1, Comp1> &c) 
+
+    /// \brief Constructs the map from another \ref SparseMap.
+    template<typename V1, typename Comp1>
+    SparseMap(const SparseMap<Key, V1, Comp1> &c)
       : _map(c._map.begin(), c._map.end()), _value(c._value) {}
 
   private:
 
-    StdMap& operator=(const StdMap&);
+    SparseMap& operator=(const SparseMap&);
 
   public:
@@ -220,5 +405,5 @@
     }
 
-    /// \e 
+    ///\e
     ConstReference operator[](const Key &k) const {
       typename Map::const_iterator it = _map.find(k);
@@ -229,147 +414,46 @@
     }
 
-    /// \e 
-    void set(const Key &k, const T &t) {
+    ///\e
+    void set(const Key &k, const Value &v) {
       typename Map::iterator it = _map.lower_bound(k);
       if (it != _map.end() && !_map.key_comp()(k, it->first))
-	it->second = t;
+	it->second = v;
       else
-	_map.insert(it, std::make_pair(k, t));
+	_map.insert(it, std::make_pair(k, v));
     }
 
-    /// \e
-    void setAll(const T &t) {
-      _value = t;
+    ///\e
+    void setAll(const Value &v) {
+      _value = v;
       _map.clear();
-    }    
-
-  };
-  
-  ///Returns a \c StdMap class
-
-  ///This function just returns a \c StdMap class with specified 
-  ///default value.
-  ///\relates StdMap
-  template<typename K, typename V, typename Compare> 
-  inline StdMap<K, V, Compare> stdMap(const V& value = V()) {
-    return StdMap<K, V, Compare>(value);
-  }
-  
-  ///Returns a \c StdMap class
-
-  ///This function just returns a \c StdMap class with specified 
-  ///default value.
-  ///\relates StdMap
-  template<typename K, typename V> 
-  inline StdMap<K, V, std::less<K> > stdMap(const V& value = V()) {
-    return StdMap<K, V, std::less<K> >(value);
-  }
-  
-  ///Returns a \c StdMap class created from an appropriate std::map
-
-  ///This function just returns a \c StdMap class created from an 
-  ///appropriate std::map.
-  ///\relates StdMap
-  template<typename K, typename V, typename Compare> 
-  inline StdMap<K, V, Compare> stdMap( const std::map<K, V, Compare> &map, 
-                                       const V& value = V() ) {
-    return StdMap<K, V, Compare>(map, value);
-  }
-
-  ///Returns a \c StdMap class created from an appropriate std::map
-
-  ///This function just returns a \c StdMap class created from an 
-  ///appropriate std::map.
-  ///\relates StdMap
-  template<typename K, typename V> 
-  inline StdMap<K, V, std::less<K> > stdMap( const std::map<K, V, std::less<K> > &map, 
-                                             const V& value = V() ) {
-    return StdMap<K, V, std::less<K> >(map, value);
-  }
-
-  /// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt>
-  ///
-  /// This map has the <tt>[0..size-1]</tt> keyset and the values
-  /// are stored in a \c std::vector<T>  container. It can be used with
-  /// some data structures, for example \c UnionFind, \c BinHeap, when 
-  /// the used items are small integer numbers.
-  /// This map meets the \ref concepts::ReferenceMap "ReferenceMap" concept.
-  ///
-  /// \todo Revise its name
-  template <typename T>
-  class IntegerMap : public MapBase<int, T> {
-
-    template <typename T1>
-    friend class IntegerMap;
-
-  public:
-
-    typedef MapBase<int, T> Parent;
-    ///\e
-    typedef typename Parent::Key Key;
-    ///\e
-    typedef typename Parent::Value Value;
-    ///\e
-    typedef T& Reference;
-    ///\e
-    typedef const T& ConstReference;
-
-    typedef True ReferenceMapTag;
-
-  private:
-    
-    typedef std::vector<T> Vector;
-    Vector _vector;
-
-  public:
-
-    /// Constructor with specified default value
-    IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {}
-
-    /// \brief Constructs the map from an appropriate \c std::vector.
-    template <typename T1>
-    IntegerMap(const std::vector<T1>& vector) 
-      : _vector(vector.begin(), vector.end()) {}
-    
-    /// \brief Constructs a map from an other \ref IntegerMap.
-    template <typename T1>
-    IntegerMap(const IntegerMap<T1> &c) 
-      : _vector(c._vector.begin(), c._vector.end()) {}
-
-    /// \brief Resize the container
-    void resize(int size, const T& value = T()) {
-      _vector.resize(size, value);
     }
-
-  private:
-
-    IntegerMap& operator=(const IntegerMap&);
-
-  public:
-
-    ///\e
-    Reference operator[](Key k) {
-      return _vector[k];
-    }
-
-    /// \e 
-    ConstReference operator[](Key k) const {
-      return _vector[k];
-    }
-
-    /// \e 
-    void set(const Key &k, const T& t) {
-      _vector[k] = t;
-    }
-
-  };
-  
-  ///Returns an \c IntegerMap class
-
-  ///This function just returns an \c IntegerMap class.
-  ///\relates IntegerMap
-  template<typename T>
-  inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) {
-    return IntegerMap<T>(size, value);
+  };
+
+  /// Returns a \ref SparseMap class
+
+  /// This function just returns a \ref SparseMap class with specified
+  /// default value.
+  /// \relates SparseMap
+  template<typename K, typename V, typename Compare>
+  inline SparseMap<K, V, Compare> sparseMap(const V& value = V()) {
+    return SparseMap<K, V, Compare>(value);
+  }
+
+  template<typename K, typename V>
+  inline SparseMap<K, V, std::less<K> > sparseMap(const V& value = V()) {
+    return SparseMap<K, V, std::less<K> >(value);
+  }
+
+  /// \brief Returns a \ref SparseMap class created from an appropriate
+  /// \c std::map
+
+  /// This function just returns a \ref SparseMap class created from an
+  /// appropriate \c std::map.
+  /// \relates SparseMap
+  template<typename K, typename V, typename Compare>
+  inline SparseMap<K, V, Compare>
+    sparseMap(const std::map<K, V, Compare> &map, const V& value = V())
+  {
+    return SparseMap<K, V, Compare>(map, value);
   }
 
@@ -379,78 +463,210 @@
   /// @{
 
-  /// \brief Identity map.
-  ///
-  /// This map gives back the given key as value without any
-  /// modification. 
-  template <typename T>
-  class IdentityMap : public MapBase<T, T> {
-  public:
-    typedef MapBase<T, T> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    /// \e
-    const T& operator[](const T& t) const {
-      return t;
-    }
-  };
-
-  ///Returns an \c IdentityMap class
-
-  ///This function just returns an \c IdentityMap class.
-  ///\relates IdentityMap
-  template<typename T>
-  inline IdentityMap<T> identityMap() {
-    return IdentityMap<T>();
-  }
-  
-
-  ///\brief Convert the \c Value of a map to another type using
-  ///the default conversion.
-  ///
-  ///This \ref concepts::ReadMap "read only map"
-  ///converts the \c Value of a map to type \c T.
-  ///Its \c Key is inherited from \c M.
-  template <typename M, typename T> 
-  class ConvertMap : public MapBase<typename M::Key, T> {
-    const M& m;
-  public:
-    typedef MapBase<typename M::Key, T> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-
-    ///Constructor.
-    ///\param _m is the underlying map.
-    ConvertMap(const M &_m) : m(_m) {};
-
-    ///\e
-    Value operator[](const Key& k) const {return m[k];}
-  };
-  
-  ///Returns a \c ConvertMap class
-
-  ///This function just returns a \c ConvertMap class.
-  ///\relates ConvertMap
-  template<typename T, typename M>
-  inline ConvertMap<M, T> convertMap(const M &m) {
-    return ConvertMap<M, T>(m);
-  }
-
-  ///Simple wrapping of a map
-
-  ///This \ref concepts::ReadMap "read only map" returns the simple
-  ///wrapping of the given map. Sometimes the reference maps cannot be
-  ///combined with simple read maps. This map adaptor wraps the given
-  ///map to simple read map.
-  ///
-  ///\sa SimpleWriteMap
-  ///
-  /// \todo Revise the misleading name 
-  template<typename M> 
-  class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
-    const M& m;
-
+  /// Composition of two maps
+
+  /// This \ref concepts::ReadMap "read-only map" returns the
+  /// composition of two given maps. That is to say, if \c m1 is of
+  /// type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   ComposeMap<M1, M2> cm(m1,m2);
+  /// \endcode
+  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>.
+  ///
+  /// The \c Key type of the map is inherited from \c M2 and the
+  /// \c Value type is from \c M1.
+  /// \c M2::Value must be convertible to \c M1::Key.
+  ///
+  /// The simplest way of using this map is through the composeMap()
+  /// function.
+  ///
+  /// \sa CombineMap
+  ///
+  /// \todo Check the requirements.
+  template <typename M1, typename M2>
+  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
+    const M1 &_m1;
+    const M2 &_m2;
+  public:
+    typedef MapBase<typename M2::Key, typename M1::Value> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+    ComposeMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
+
+    /// \e
+    typename MapTraits<M1>::ConstReturnValue
+    operator[](const Key &k) const { return _m1[_m2[k]]; }
+  };
+
+  /// Returns a \ref ComposeMap class
+
+  /// This function just returns a \ref ComposeMap class.
+  ///
+  /// If \c m1 and \c m2 are maps and the \c Value type of \c m2 is
+  /// convertible to the \c Key of \c m1, then <tt>composeMap(m1,m2)[x]</tt>
+  /// will be equal to <tt>m1[m2[x]]</tt>.
+  ///
+  /// \relates ComposeMap
+  template <typename M1, typename M2>
+  inline ComposeMap<M1, M2> composeMap(const M1 &m1, const M2 &m2) {
+    return ComposeMap<M1, M2>(m1, m2);
+  }
+
+
+  /// Combination of two maps using an STL (binary) functor.
+
+  /// This \ref concepts::ReadMap "read-only map" takes two maps and a
+  /// binary functor and returns the combination of the two given maps
+  /// using the functor.
+  /// That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2
+  /// and \c f is of \c F, then for
+  /// \code
+  ///   CombineMap<M1,M2,F,V> cm(m1,m2,f);
+  /// \endcode
+  /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>.
+  ///
+  /// The \c Key type of the map is inherited from \c M1 (\c M1::Key
+  /// must be convertible to \c M2::Key) and the \c Value type is \c V.
+  /// \c M2::Value and \c M1::Value must be convertible to the
+  /// corresponding input parameter of \c F and the return type of \c F
+  /// must be convertible to \c V.
+  ///
+  /// The simplest way of using this map is through the combineMap()
+  /// function.
+  ///
+  /// \sa ComposeMap
+  ///
+  /// \todo Check the requirements.
+  template<typename M1, typename M2, typename F,
+	   typename V = typename F::result_type>
+  class CombineMap : public MapBase<typename M1::Key, V> {
+    const M1 &_m1;
+    const M2 &_m2;
+    F _f;
+  public:
+    typedef MapBase<typename M1::Key, V> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+    CombineMap(const M1 &m1, const M2 &m2, const F &f = F())
+      : _m1(m1), _m2(m2), _f(f) {}
+    /// \e
+    Value operator[](const Key &k) const { return _f(_m1[k],_m2[k]); }
+  };
+
+  /// Returns a \ref CombineMap class
+
+  /// This function just returns a \ref CombineMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are both maps with \c double
+  /// values, then
+  /// \code
+  ///   combineMap(m1,m2,std::plus<double>())
+  /// \endcode
+  /// is equivalent to
+  /// \code
+  ///   addMap(m1,m2)
+  /// \endcode
+  ///
+  /// This function is specialized for adaptable binary function
+  /// classes and C++ functions.
+  ///
+  /// \relates CombineMap
+  template<typename M1, typename M2, typename F, typename V>
+  inline CombineMap<M1, M2, F, V>
+  combineMap(const M1 &m1, const M2 &m2, const F &f) {
+    return CombineMap<M1, M2, F, V>(m1,m2,f);
+  }
+
+  template<typename M1, typename M2, typename F>
+  inline CombineMap<M1, M2, F, typename F::result_type>
+  combineMap(const M1 &m1, const M2 &m2, const F &f) {
+    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
+  }
+
+  template<typename M1, typename M2, typename K1, typename K2, typename V>
+  inline CombineMap<M1, M2, V (*)(K1, K2), V>
+  combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
+    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
+  }
+
+
+  /// Converts an STL style (unary) functor to a map
+
+  /// This \ref concepts::ReadMap "read-only map" returns the value
+  /// of a given functor. Actually, it just wraps the functor and
+  /// provides the \c Key and \c Value typedefs.
+  ///
+  /// Template parameters \c K and \c V will become its \c Key and
+  /// \c Value. In most cases they have to be given explicitly because
+  /// a functor typically does not provide \c argument_type and
+  /// \c result_type typedefs.
+  /// Parameter \c F is the type of the used functor.
+  ///
+  /// The simplest way of using this map is through the functorToMap()
+  /// function.
+  ///
+  /// \sa MapToFunctor
+  template<typename F,
+	   typename K = typename F::argument_type,
+	   typename V = typename F::result_type>
+  class FunctorToMap : public MapBase<K, V> {
+    const F &_f;
+  public:
+    typedef MapBase<K, V> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+    FunctorToMap(const F &f = F()) : _f(f) {}
+    /// \e
+    Value operator[](const Key &k) const { return _f(k); }
+  };
+
+  /// Returns a \ref FunctorToMap class
+
+  /// This function just returns a \ref FunctorToMap class.
+  ///
+  /// This function is specialized for adaptable binary function
+  /// classes and C++ functions.
+  ///
+  /// \relates FunctorToMap
+  template<typename K, typename V, typename F>
+  inline FunctorToMap<F, K, V> functorToMap(const F &f) {
+    return FunctorToMap<F, K, V>(f);
+  }
+
+  template <typename F>
+  inline FunctorToMap<F, typename F::argument_type, typename F::result_type>
+    functorToMap(const F &f)
+  {
+    return FunctorToMap<F, typename F::argument_type,
+      typename F::result_type>(f);
+  }
+
+  template <typename K, typename V>
+  inline FunctorToMap<V (*)(K), K, V> functorToMap(V (*f)(K)) {
+    return FunctorToMap<V (*)(K), K, V>(f);
+  }
+
+
+  /// Converts a map to an STL style (unary) functor
+
+  /// This class converts a map to an STL style (unary) functor.
+  /// That is it provides an <tt>operator()</tt> to read its values.
+  ///
+  /// For the sake of convenience it also works as a usual
+  /// \ref concepts::ReadMap "readable map", i.e. <tt>operator[]</tt>
+  /// and the \c Key and \c Value typedefs also exist.
+  ///
+  /// The simplest way of using this map is through the mapToFunctor()
+  /// function.
+  ///
+  ///\sa FunctorToMap
+  template <typename M>
+  class MapToFunctor : public MapBase<typename M::Key, typename M::Value> {
+    const M &_m;
   public:
     typedef MapBase<typename M::Key, typename M::Value> Parent;
@@ -458,66 +674,127 @@
     typedef typename Parent::Value Value;
 
-    ///Constructor
-    SimpleMap(const M &_m) : m(_m) {};
-    ///\e
-    Value operator[](Key k) const {return m[k];}
-  };
-  
-  ///Returns a \c SimpleMap class
-
-  ///This function just returns a \c SimpleMap class.
-  ///\relates SimpleMap
+    typedef typename Parent::Key argument_type;
+    typedef typename Parent::Value result_type;
+
+    /// Constructor
+    MapToFunctor(const M &m) : _m(m) {}
+    /// \e
+    Value operator()(const Key &k) const { return _m[k]; }
+    /// \e
+    Value operator[](const Key &k) const { return _m[k]; }
+  };
+
+  /// Returns a \ref MapToFunctor class
+
+  /// This function just returns a \ref MapToFunctor class.
+  /// \relates MapToFunctor
   template<typename M>
-  inline SimpleMap<M> simpleMap(const M &m) {
-    return SimpleMap<M>(m);
-  }
-
-  ///Simple writable wrapping of a map
-
-  ///This \ref concepts::ReadWriteMap "read-write map" returns the simple
-  ///wrapping of the given map. Sometimes the reference maps cannot be
-  ///combined with simple read-write maps. This map adaptor wraps the
-  ///given map to simple read-write map.
-  ///
-  ///\sa SimpleMap
-  ///
-  /// \todo Revise the misleading name
-  template<typename M> 
-  class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
-    M& m;
-
-  public:
-    typedef MapBase<typename M::Key, typename M::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-    SimpleWriteMap(M &_m) : m(_m) {};
-    ///\e
-    Value operator[](Key k) const {return m[k];}
-    ///\e
-    void set(Key k, const Value& c) { m.set(k, c); }
-  };
-
-  ///Returns a \c SimpleWriteMap class
-
-  ///This function just returns a \c SimpleWriteMap class.
-  ///\relates SimpleWriteMap
-  template<typename M>
-  inline SimpleWriteMap<M> simpleWriteMap(M &m) {
-    return SimpleWriteMap<M>(m);
-  }
-
-  ///Sum of two maps
-
-  ///This \ref concepts::ReadMap "read only map" returns the sum of the two
-  ///given maps.
-  ///Its \c Key and \c Value are inherited from \c M1.
-  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
-  template<typename M1, typename M2> 
+  inline MapToFunctor<M> mapToFunctor(const M &m) {
+    return MapToFunctor<M>(m);
+  }
+
+
+  /// \brief Map adaptor to convert the \c Value type of a map to
+  /// another type using the default conversion.
+
+  /// Map adaptor to convert the \c Value type of a \ref concepts::ReadMap
+  /// "readable map" to another type using the default conversion.
+  /// The \c Key type of it is inherited from \c M and the \c Value
+  /// type is \c V.
+  /// This type conforms the \ref concepts::ReadMap "ReadMap" concept.
+  ///
+  /// The simplest way of using this map is through the convertMap()
+  /// function.
+  template <typename M, typename V>
+  class ConvertMap : public MapBase<typename M::Key, V> {
+    const M &_m;
+  public:
+    typedef MapBase<typename M::Key, V> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+
+    /// Constructor.
+    /// \param m The underlying map.
+    ConvertMap(const M &m) : _m(m) {}
+
+    /// \e
+    Value operator[](const Key &k) const { return _m[k]; }
+  };
+
+  /// Returns a \ref ConvertMap class
+
+  /// This function just returns a \ref ConvertMap class.
+  /// \relates ConvertMap
+  template<typename V, typename M>
+  inline ConvertMap<M, V> convertMap(const M &map) {
+    return ConvertMap<M, V>(map);
+  }
+
+
+  /// Applies all map setting operations to two maps
+
+  /// This map has two \ref concepts::WriteMap "writable map" parameters
+  /// and each write request will be passed to both of them.
+  /// If \c M1 is also \ref concepts::ReadMap "readable", then the read
+  /// operations will return the corresponding values of \c M1.
+  ///
+  /// The \c Key and \c Value types are inherited from \c M1.
+  /// The \c Key and \c Value of \c M2 must be convertible from those
+  /// of \c M1.
+  ///
+  /// The simplest way of using this map is through the forkMap()
+  /// function.
+  template<typename  M1, typename M2>
+  class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
+    M1 &_m1;
+    M2 &_m2;
+  public:
+    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+    ForkMap(M1 &m1, M2 &m2) : _m1(m1), _m2(m2) {}
+    /// Returns the value associated with the given key in the first map.
+    Value operator[](const Key &k) const { return _m1[k]; }
+    /// Sets the value associated with the given key in both maps.
+    void set(const Key &k, const Value &v) { _m1.set(k,v); _m2.set(k,v); }
+  };
+
+  /// Returns a \ref ForkMap class
+
+  /// This function just returns a \ref ForkMap class.
+  /// \relates ForkMap
+  template <typename M1, typename M2>
+  inline ForkMap<M1,M2> forkMap(M1 &m1, M2 &m2) {
+    return ForkMap<M1,M2>(m1,m2);
+  }
+
+
+  /// Sum of two maps
+
+  /// This \ref concepts::ReadMap "read-only map" returns the sum
+  /// of the values of the two given maps.
+  /// Its \c Key and \c Value types are inherited from \c M1.
+  /// The \c Key and \c Value of \c M2 must be convertible to those of
+  /// \c M1.
+  ///
+  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   AddMap<M1,M2> am(m1,m2);
+  /// \endcode
+  /// <tt>am[x]</tt> will be equal to <tt>m1[x]+m2[x]</tt>.
+  ///
+  /// The simplest way of using this map is through the addMap()
+  /// function.
+  ///
+  /// \sa SubMap, MulMap, DivMap
+  /// \sa ShiftMap, ShiftWriteMap
+  template<typename M1, typename M2>
   class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
-    const M1& m1;
-    const M2& m2;
-
+    const M1 &_m1;
+    const M2 &_m2;
   public:
     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
@@ -525,115 +802,47 @@
     typedef typename Parent::Value Value;
 
-    ///Constructor
-    AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    ///\e
-    Value operator[](Key k) const {return m1[k]+m2[k];}
-  };
-  
-  ///Returns an \c AddMap class
-
-  ///This function just returns an \c AddMap class.
-  ///\todo Extend the documentation: how to call these type of functions?
-  ///
-  ///\relates AddMap
-  template<typename M1, typename M2> 
-  inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
+    /// Constructor
+    AddMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m1[k]+_m2[k]; }
+  };
+
+  /// Returns an \ref AddMap class
+
+  /// This function just returns an \ref AddMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are both maps with \c double
+  /// values, then <tt>addMap(m1,m2)[x]</tt> will be equal to
+  /// <tt>m1[x]+m2[x]</tt>.
+  ///
+  /// \relates AddMap
+  template<typename M1, typename M2>
+  inline AddMap<M1, M2> addMap(const M1 &m1, const M2 &m2) {
     return AddMap<M1, M2>(m1,m2);
   }
 
-  ///Shift a map with a constant.
-
-  ///This \ref concepts::ReadMap "read only map" returns the sum of the
-  ///given map and a constant value.
-  ///Its \c Key and \c Value are inherited from \c M.
-  ///
-  ///Actually,
-  ///\code
-  ///  ShiftMap<X> sh(x,v);
-  ///\endcode
-  ///is equivalent to
-  ///\code
-  ///  ConstMap<X::Key, X::Value> c_tmp(v);
-  ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
-  ///\endcode
-  ///
-  ///\sa ShiftWriteMap
-  template<typename M, typename C = typename M::Value> 
-  class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
-    const M& m;
-    C v;
-  public:
-    typedef MapBase<typename M::Key, typename M::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-
-    ///Constructor.
-    ///\param _m is the undelying map.
-    ///\param _v is the shift value.
-    ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
-    ///\e
-    Value operator[](Key k) const {return m[k] + v;}
-  };
-
-  ///Shift a map with a constant (ReadWrite version).
-
-  ///This \ref concepts::ReadWriteMap "read-write map" returns the sum of the
-  ///given map and a constant value. It makes also possible to write the map.
-  ///Its \c Key and \c Value are inherited from \c M.
-  ///
-  ///\sa ShiftMap
-  template<typename M, typename C = typename M::Value> 
-  class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
-    M& m;
-    C v;
-  public:
-    typedef MapBase<typename M::Key, typename M::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-
-    ///Constructor.
-    ///\param _m is the undelying map.
-    ///\param _v is the shift value.
-    ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
-    /// \e
-    Value operator[](Key k) const {return m[k] + v;}
-    /// \e
-    void set(Key k, const Value& c) { m.set(k, c - v); }
-  };
-  
-  ///Returns a \c ShiftMap class
-
-  ///This function just returns a \c ShiftMap class.
-  ///\relates ShiftMap
-  template<typename M, typename C> 
-  inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
-    return ShiftMap<M, C>(m,v);
-  }
-
-  ///Returns a \c ShiftWriteMap class
-
-  ///This function just returns a \c ShiftWriteMap class.
-  ///\relates ShiftWriteMap
-  template<typename M, typename C> 
-  inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) {
-    return ShiftWriteMap<M, C>(m,v);
-  }
-
-  ///Difference of two maps
-
-  ///This \ref concepts::ReadMap "read only map" returns the difference
-  ///of the values of the two given maps.
-  ///Its \c Key and \c Value are inherited from \c M1.
-  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
-  ///
-  /// \todo Revise the misleading name
-  template<typename M1, typename M2> 
+
+  /// Difference of two maps
+
+  /// This \ref concepts::ReadMap "read-only map" returns the difference
+  /// of the values of the two given maps.
+  /// Its \c Key and \c Value types are inherited from \c M1.
+  /// The \c Key and \c Value of \c M2 must be convertible to those of
+  /// \c M1.
+  ///
+  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   SubMap<M1,M2> sm(m1,m2);
+  /// \endcode
+  /// <tt>sm[x]</tt> will be equal to <tt>m1[x]-m2[x]</tt>.
+  ///
+  /// The simplest way of using this map is through the subMap()
+  /// function.
+  ///
+  /// \sa AddMap, MulMap, DivMap
+  template<typename M1, typename M2>
   class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
-    const M1& m1;
-    const M2& m2;
+    const M1 &_m1;
+    const M2 &_m2;
   public:
     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
@@ -641,30 +850,48 @@
     typedef typename Parent::Value Value;
 
-    ///Constructor
-    SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    /// \e
-    Value operator[](Key k) const {return m1[k]-m2[k];}
-  };
-  
-  ///Returns a \c SubMap class
-
-  ///This function just returns a \c SubMap class.
-  ///
-  ///\relates SubMap
-  template<typename M1, typename M2> 
+    /// Constructor
+    SubMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m1[k]-_m2[k]; }
+  };
+
+  /// Returns a \ref SubMap class
+
+  /// This function just returns a \ref SubMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are both maps with \c double
+  /// values, then <tt>subMap(m1,m2)[x]</tt> will be equal to
+  /// <tt>m1[x]-m2[x]</tt>.
+  ///
+  /// \relates SubMap
+  template<typename M1, typename M2>
   inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
-    return SubMap<M1, M2>(m1, m2);
-  }
-
-  ///Product of two maps
-
-  ///This \ref concepts::ReadMap "read only map" returns the product of the
-  ///values of the two given maps.
-  ///Its \c Key and \c Value are inherited from \c M1.
-  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
-  template<typename M1, typename M2> 
+    return SubMap<M1, M2>(m1,m2);
+  }
+
+
+  /// Product of two maps
+
+  /// This \ref concepts::ReadMap "read-only map" returns the product
+  /// of the values of the two given maps.
+  /// Its \c Key and \c Value types are inherited from \c M1.
+  /// The \c Key and \c Value of \c M2 must be convertible to those of
+  /// \c M1.
+  ///
+  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   MulMap<M1,M2> mm(m1,m2);
+  /// \endcode
+  /// <tt>mm[x]</tt> will be equal to <tt>m1[x]*m2[x]</tt>.
+  ///
+  /// The simplest way of using this map is through the mulMap()
+  /// function.
+  ///
+  /// \sa AddMap, SubMap, DivMap
+  /// \sa ScaleMap, ScaleWriteMap
+  template<typename M1, typename M2>
   class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
-    const M1& m1;
-    const M2& m2;
+    const M1 &_m1;
+    const M2 &_m2;
   public:
     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
@@ -672,113 +899,47 @@
     typedef typename Parent::Value Value;
 
-    ///Constructor
-    MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    /// \e
-    Value operator[](Key k) const {return m1[k]*m2[k];}
-  };
-  
-  ///Returns a \c MulMap class
-
-  ///This function just returns a \c MulMap class.
-  ///\relates MulMap
-  template<typename M1, typename M2> 
+    /// Constructor
+    MulMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m1[k]*_m2[k]; }
+  };
+
+  /// Returns a \ref MulMap class
+
+  /// This function just returns a \ref MulMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are both maps with \c double
+  /// values, then <tt>mulMap(m1,m2)[x]</tt> will be equal to
+  /// <tt>m1[x]*m2[x]</tt>.
+  ///
+  /// \relates MulMap
+  template<typename M1, typename M2>
   inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
     return MulMap<M1, M2>(m1,m2);
   }
- 
-  ///Scales a map with a constant.
-
-  ///This \ref concepts::ReadMap "read only map" returns the value of the
-  ///given map multiplied from the left side with a constant value.
-  ///Its \c Key and \c Value are inherited from \c M.
-  ///
-  ///Actually,
-  ///\code
-  ///  ScaleMap<X> sc(x,v);
-  ///\endcode
-  ///is equivalent to
-  ///\code
-  ///  ConstMap<X::Key, X::Value> c_tmp(v);
-  ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
-  ///\endcode
-  ///
-  ///\sa ScaleWriteMap
-  template<typename M, typename C = typename M::Value> 
-  class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
-    const M& m;
-    C v;
-  public:
-    typedef MapBase<typename M::Key, typename M::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-
-    ///Constructor.
-    ///\param _m is the undelying map.
-    ///\param _v is the scaling value.
-    ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
-    /// \e
-    Value operator[](Key k) const {return v * m[k];}
-  };
-
-  ///Scales a map with a constant (ReadWrite version).
-
-  ///This \ref concepts::ReadWriteMap "read-write map" returns the value of the
-  ///given map multiplied from the left side with a constant value. It can
-  ///also be used as write map if the \c / operator is defined between
-  ///\c Value and \c C and the given multiplier is not zero.
-  ///Its \c Key and \c Value are inherited from \c M.
-  ///
-  ///\sa ScaleMap
-  template<typename M, typename C = typename M::Value> 
-  class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
-    M& m;
-    C v;
-  public:
-    typedef MapBase<typename M::Key, typename M::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-
-    ///Constructor.
-    ///\param _m is the undelying map.
-    ///\param _v is the scaling value.
-    ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
-    /// \e
-    Value operator[](Key k) const {return v * m[k];}
-    /// \e
-    void set(Key k, const Value& c) { m.set(k, c / v);}
-  };
-  
-  ///Returns a \c ScaleMap class
-
-  ///This function just returns a \c ScaleMap class.
-  ///\relates ScaleMap
-  template<typename M, typename C> 
-  inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
-    return ScaleMap<M, C>(m,v);
-  }
-
-  ///Returns a \c ScaleWriteMap class
-
-  ///This function just returns a \c ScaleWriteMap class.
-  ///\relates ScaleWriteMap
-  template<typename M, typename C> 
-  inline ScaleWriteMap<M, C> scaleMap(M &m,const C &v) {
-    return ScaleWriteMap<M, C>(m,v);
-  }
-
-  ///Quotient of two maps
-
-  ///This \ref concepts::ReadMap "read only map" returns the quotient of the
-  ///values of the two given maps.
-  ///Its \c Key and \c Value are inherited from \c M1.
-  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
-  template<typename M1, typename M2> 
+
+
+  /// Quotient of two maps
+
+  /// This \ref concepts::ReadMap "read-only map" returns the quotient
+  /// of the values of the two given maps.
+  /// Its \c Key and \c Value types are inherited from \c M1.
+  /// The \c Key and \c Value of \c M2 must be convertible to those of
+  /// \c M1.
+  ///
+  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   DivMap<M1,M2> dm(m1,m2);
+  /// \endcode
+  /// <tt>dm[x]</tt> will be equal to <tt>m1[x]/m2[x]</tt>.
+  ///
+  /// The simplest way of using this map is through the divMap()
+  /// function.
+  ///
+  /// \sa AddMap, SubMap, MulMap
+  template<typename M1, typename M2>
   class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
-    const M1& m1;
-    const M2& m2;
+    const M1 &_m1;
+    const M2 &_m2;
   public:
     typedef MapBase<typename M1::Key, typename M1::Value> Parent;
@@ -786,154 +947,250 @@
     typedef typename Parent::Value Value;
 
-    ///Constructor
-    DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    /// \e
-    Value operator[](Key k) const {return m1[k]/m2[k];}
-  };
-  
-  ///Returns a \c DivMap class
-
-  ///This function just returns a \c DivMap class.
-  ///\relates DivMap
-  template<typename M1, typename M2> 
+    /// Constructor
+    DivMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m1[k]/_m2[k]; }
+  };
+
+  /// Returns a \ref DivMap class
+
+  /// This function just returns a \ref DivMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are both maps with \c double
+  /// values, then <tt>divMap(m1,m2)[x]</tt> will be equal to
+  /// <tt>m1[x]/m2[x]</tt>.
+  ///
+  /// \relates DivMap
+  template<typename M1, typename M2>
   inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
     return DivMap<M1, M2>(m1,m2);
   }
-  
-  ///Composition of two maps
-
-  ///This \ref concepts::ReadMap "read only map" returns the composition of
-  ///two given maps.
-  ///That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2,
-  ///then for
-  ///\code
-  ///  ComposeMap<M1, M2> cm(m1,m2);
-  ///\endcode
-  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>.
-  ///
-  ///Its \c Key is inherited from \c M2 and its \c Value is from \c M1.
-  ///\c M2::Value must be convertible to \c M1::Key.
-  ///
-  ///\sa CombineMap
-  ///
-  ///\todo Check the requirements.
-  template <typename M1, typename M2> 
-  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
-    const M1& m1;
-    const M2& m2;
-  public:
-    typedef MapBase<typename M2::Key, typename M1::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-    ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
-    
-    /// \e
-
-
-    /// \todo Use the  MapTraits once it is ported.
-    ///
-
-    //typename MapTraits<M1>::ConstReturnValue
-    typename M1::Value
-    operator[](Key k) const {return m1[m2[k]];}
-  };
-
-  ///Returns a \c ComposeMap class
-
-  ///This function just returns a \c ComposeMap class.
-  ///\relates ComposeMap
-  template <typename M1, typename M2> 
-  inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
-    return ComposeMap<M1, M2>(m1,m2);
-  }
-  
-  ///Combine of two maps using an STL (binary) functor.
-
-  ///Combine of two maps using an STL (binary) functor.
-  ///
-  ///This \ref concepts::ReadMap "read only map" takes two maps and a
-  ///binary functor and returns the composition of the two
-  ///given maps unsing the functor. 
-  ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
-  ///and \c f is of \c F, then for
-  ///\code
-  ///  CombineMap<M1,M2,F,V> cm(m1,m2,f);
-  ///\endcode
-  /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
-  ///
-  ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
-  ///\c M2::Value and \c M1::Value must be convertible to the corresponding
-  ///input parameter of \c F and the return type of \c F must be convertible
-  ///to \c V.
-  ///
-  ///\sa ComposeMap
-  ///
-  ///\todo Check the requirements.
-  template<typename M1, typename M2, typename F,
-	   typename V = typename F::result_type> 
-  class CombineMap : public MapBase<typename M1::Key, V> {
-    const M1& m1;
-    const M2& m2;
-    F f;
-  public:
-    typedef MapBase<typename M1::Key, V> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-    CombineMap(const M1 &_m1,const M2 &_m2,const F &_f = F())
-      : m1(_m1), m2(_m2), f(_f) {};
-    /// \e
-    Value operator[](Key k) const {return f(m1[k],m2[k]);}
-  };
-  
-  ///Returns a \c CombineMap class
-
-  ///This function just returns a \c CombineMap class.
-  ///
-  ///For example if \c m1 and \c m2 are both \c double valued maps, then 
-  ///\code
-  ///combineMap(m1,m2,std::plus<double>())
-  ///\endcode
-  ///is equivalent to
-  ///\code
-  ///addMap(m1,m2)
-  ///\endcode
-  ///
-  ///This function is specialized for adaptable binary function
-  ///classes and C++ functions.
-  ///
-  ///\relates CombineMap
-  template<typename M1, typename M2, typename F, typename V> 
-  inline CombineMap<M1, M2, F, V> 
-  combineMap(const M1& m1,const M2& m2, const F& f) {
-    return CombineMap<M1, M2, F, V>(m1,m2,f);
-  }
-
-  template<typename M1, typename M2, typename F> 
-  inline CombineMap<M1, M2, F, typename F::result_type> 
-  combineMap(const M1& m1, const M2& m2, const F& f) {
-    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
-  }
-
-  template<typename M1, typename M2, typename K1, typename K2, typename V> 
-  inline CombineMap<M1, M2, V (*)(K1, K2), V> 
-  combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
-    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
-  }
-
-  ///Negative value of a map
-
-  ///This \ref concepts::ReadMap "read only map" returns the negative
-  ///value of the value returned by the given map.
-  ///Its \c Key and \c Value are inherited from \c M.
-  ///The unary \c - operator must be defined for \c Value, of course.
-  ///
-  ///\sa NegWriteMap
-  template<typename M> 
+
+
+  /// Shifts a map with a constant.
+
+  /// This \ref concepts::ReadMap "read-only map" returns the sum of
+  /// the given map and a constant value (i.e. it shifts the map with
+  /// the constant). Its \c Key and \c Value are inherited from \c M.
+  ///
+  /// Actually,
+  /// \code
+  ///   ShiftMap<M> sh(m,v);
+  /// \endcode
+  /// is equivalent to
+  /// \code
+  ///   ConstMap<M::Key, M::Value> cm(v);
+  ///   AddMap<M, ConstMap<M::Key, M::Value> > sh(m,cm);
+  /// \endcode
+  ///
+  /// The simplest way of using this map is through the shiftMap()
+  /// function.
+  ///
+  /// \sa ShiftWriteMap
+  template<typename M, typename C = typename M::Value>
+  class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
+    const M &_m;
+    C _v;
+  public:
+    typedef MapBase<typename M::Key, typename M::Value> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+
+    /// Constructor.
+    /// \param m The undelying map.
+    /// \param v The constant value.
+    ShiftMap(const M &m, const C &v) : _m(m), _v(v) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m[k]+_v; }
+  };
+
+  /// Shifts a map with a constant (read-write version).
+
+  /// This \ref concepts::ReadWriteMap "read-write map" returns the sum
+  /// of the given map and a constant value (i.e. it shifts the map with
+  /// the constant). Its \c Key and \c Value are inherited from \c M.
+  /// It makes also possible to write the map.
+  ///
+  /// The simplest way of using this map is through the shiftWriteMap()
+  /// function.
+  ///
+  /// \sa ShiftMap
+  template<typename M, typename C = typename M::Value>
+  class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
+    M &_m;
+    C _v;
+  public:
+    typedef MapBase<typename M::Key, typename M::Value> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+
+    /// Constructor.
+    /// \param m The undelying map.
+    /// \param v The constant value.
+    ShiftWriteMap(M &m, const C &v) : _m(m), _v(v) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m[k]+_v; }
+    /// \e
+    void set(const Key &k, const Value &v) { _m.set(k, v-_v); }
+  };
+
+  /// Returns a \ref ShiftMap class
+
+  /// This function just returns a \ref ShiftMap class.
+  ///
+  /// For example, if \c m is a map with \c double values and \c v is
+  /// \c double, then <tt>shiftMap(m,v)[x]</tt> will be equal to
+  /// <tt>m[x]+v</tt>.
+  ///
+  /// \relates ShiftMap
+  template<typename M, typename C>
+  inline ShiftMap<M, C> shiftMap(const M &m, const C &v) {
+    return ShiftMap<M, C>(m,v);
+  }
+
+  /// Returns a \ref ShiftWriteMap class
+
+  /// This function just returns a \ref ShiftWriteMap class.
+  ///
+  /// For example, if \c m is a map with \c double values and \c v is
+  /// \c double, then <tt>shiftWriteMap(m,v)[x]</tt> will be equal to
+  /// <tt>m[x]+v</tt>.
+  /// Moreover it makes also possible to write the map.
+  ///
+  /// \relates ShiftWriteMap
+  template<typename M, typename C>
+  inline ShiftWriteMap<M, C> shiftWriteMap(M &m, const C &v) {
+    return ShiftWriteMap<M, C>(m,v);
+  }
+
+
+  /// Scales a map with a constant.
+
+  /// This \ref concepts::ReadMap "read-only map" returns the value of
+  /// the given map multiplied from the left side with a constant value.
+  /// Its \c Key and \c Value are inherited from \c M.
+  ///
+  /// Actually,
+  /// \code
+  ///   ScaleMap<M> sc(m,v);
+  /// \endcode
+  /// is equivalent to
+  /// \code
+  ///   ConstMap<M::Key, M::Value> cm(v);
+  ///   MulMap<ConstMap<M::Key, M::Value>, M> sc(cm,m);
+  /// \endcode
+  ///
+  /// The simplest way of using this map is through the scaleMap()
+  /// function.
+  ///
+  /// \sa ScaleWriteMap
+  template<typename M, typename C = typename M::Value>
+  class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
+    const M &_m;
+    C _v;
+  public:
+    typedef MapBase<typename M::Key, typename M::Value> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+
+    /// Constructor.
+    /// \param m The undelying map.
+    /// \param v The constant value.
+    ScaleMap(const M &m, const C &v) : _m(m), _v(v) {}
+    /// \e
+    Value operator[](const Key &k) const { return _v*_m[k]; }
+  };
+
+  /// Scales a map with a constant (read-write version).
+
+  /// This \ref concepts::ReadWriteMap "read-write map" returns the value of
+  /// the given map multiplied from the left side with a constant value.
+  /// Its \c Key and \c Value are inherited from \c M.
+  /// It can also be used as write map if the \c / operator is defined
+  /// between \c Value and \c C and the given multiplier is not zero.
+  ///
+  /// The simplest way of using this map is through the scaleWriteMap()
+  /// function.
+  ///
+  /// \sa ScaleMap
+  template<typename M, typename C = typename M::Value>
+  class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
+    M &_m;
+    C _v;
+  public:
+    typedef MapBase<typename M::Key, typename M::Value> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+
+    /// Constructor.
+    /// \param m The undelying map.
+    /// \param v The constant value.
+    ScaleWriteMap(M &m, const C &v) : _m(m), _v(v) {}
+    /// \e
+    Value operator[](const Key &k) const { return _v*_m[k]; }
+    /// \e
+    void set(const Key &k, const Value &v) { _m.set(k, v/_v); }
+  };
+
+  /// Returns a \ref ScaleMap class
+
+  /// This function just returns a \ref ScaleMap class.
+  ///
+  /// For example, if \c m is a map with \c double values and \c v is
+  /// \c double, then <tt>scaleMap(m,v)[x]</tt> will be equal to
+  /// <tt>v*m[x]</tt>.
+  ///
+  /// \relates ScaleMap
+  template<typename M, typename C>
+  inline ScaleMap<M, C> scaleMap(const M &m, const C &v) {
+    return ScaleMap<M, C>(m,v);
+  }
+
+  /// Returns a \ref ScaleWriteMap class
+
+  /// This function just returns a \ref ScaleWriteMap class.
+  ///
+  /// For example, if \c m is a map with \c double values and \c v is
+  /// \c double, then <tt>scaleWriteMap(m,v)[x]</tt> will be equal to
+  /// <tt>v*m[x]</tt>.
+  /// Moreover it makes also possible to write the map.
+  ///
+  /// \relates ScaleWriteMap
+  template<typename M, typename C>
+  inline ScaleWriteMap<M, C> scaleWriteMap(M &m, const C &v) {
+    return ScaleWriteMap<M, C>(m,v);
+  }
+
+
+  /// Negative of a map
+
+  /// This \ref concepts::ReadMap "read-only map" returns the negative
+  /// of the values of the given map (using the unary \c - operator).
+  /// Its \c Key and \c Value are inherited from \c M.
+  ///
+  /// If M::Value is \c int, \c double etc., then
+  /// \code
+  ///   NegMap<M> neg(m);
+  /// \endcode
+  /// is equivalent to
+  /// \code
+  ///   ScaleMap<M> neg(m,-1);
+  /// \endcode
+  ///
+  /// The simplest way of using this map is through the negMap()
+  /// function.
+  ///
+  /// \sa NegWriteMap
+  template<typename M>
   class NegMap : public MapBase<typename M::Key, typename M::Value> {
-    const M& m;
+    const M& _m;
   public:
     typedef MapBase<typename M::Key, typename M::Value> Parent;
@@ -941,21 +1198,34 @@
     typedef typename Parent::Value Value;
 
-    ///Constructor
-    NegMap(const M &_m) : m(_m) {};
-    /// \e
-    Value operator[](Key k) const {return -m[k];}
-  };
-  
-  ///Negative value of a map (ReadWrite version)
-
-  ///This \ref concepts::ReadWriteMap "read-write map" returns the negative
-  ///value of the value returned by the given map.
-  ///Its \c Key and \c Value are inherited from \c M.
-  ///The unary \c - operator must be defined for \c Value, of course.
+    /// Constructor
+    NegMap(const M &m) : _m(m) {}
+    /// \e
+    Value operator[](const Key &k) const { return -_m[k]; }
+  };
+
+  /// Negative of a map (read-write version)
+
+  /// This \ref concepts::ReadWriteMap "read-write map" returns the
+  /// negative of the values of the given map (using the unary \c -
+  /// operator).
+  /// Its \c Key and \c Value are inherited from \c M.
+  /// It makes also possible to write the map.
+  ///
+  /// If M::Value is \c int, \c double etc., then
+  /// \code
+  ///   NegWriteMap<M> neg(m);
+  /// \endcode
+  /// is equivalent to
+  /// \code
+  ///   ScaleWriteMap<M> neg(m,-1);
+  /// \endcode
+  ///
+  /// The simplest way of using this map is through the negWriteMap()
+  /// function.
   ///
   /// \sa NegMap
-  template<typename M> 
+  template<typename M>
   class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
-    M& m;
+    M &_m;
   public:
     typedef MapBase<typename M::Key, typename M::Value> Parent;
@@ -963,40 +1233,53 @@
     typedef typename Parent::Value Value;
 
-    ///Constructor
-    NegWriteMap(M &_m) : m(_m) {};
-    /// \e
-    Value operator[](Key k) const {return -m[k];}
-    /// \e
-    void set(Key k, const Value& v) { m.set(k, -v); }
-  };
-
-  ///Returns a \c NegMap class
-
-  ///This function just returns a \c NegMap class.
-  ///\relates NegMap
-  template <typename M> 
+    /// Constructor
+    NegWriteMap(M &m) : _m(m) {}
+    /// \e
+    Value operator[](const Key &k) const { return -_m[k]; }
+    /// \e
+    void set(const Key &k, const Value &v) { _m.set(k, -v); }
+  };
+
+  /// Returns a \ref NegMap class
+
+  /// This function just returns a \ref NegMap class.
+  ///
+  /// For example, if \c m is a map with \c double values, then
+  /// <tt>negMap(m)[x]</tt> will be equal to <tt>-m[x]</tt>.
+  ///
+  /// \relates NegMap
+  template <typename M>
   inline NegMap<M> negMap(const M &m) {
     return NegMap<M>(m);
   }
 
-  ///Returns a \c NegWriteMap class
-
-  ///This function just returns a \c NegWriteMap class.
-  ///\relates NegWriteMap
-  template <typename M> 
-  inline NegWriteMap<M> negMap(M &m) {
+  /// Returns a \ref NegWriteMap class
+
+  /// This function just returns a \ref NegWriteMap class.
+  ///
+  /// For example, if \c m is a map with \c double values, then
+  /// <tt>negWriteMap(m)[x]</tt> will be equal to <tt>-m[x]</tt>.
+  /// Moreover it makes also possible to write the map.
+  ///
+  /// \relates NegWriteMap
+  template <typename M>
+  inline NegWriteMap<M> negWriteMap(M &m) {
     return NegWriteMap<M>(m);
   }
 
-  ///Absolute value of a map
-
-  ///This \ref concepts::ReadMap "read only map" returns the absolute value
-  ///of the value returned by the given map.
-  ///Its \c Key and \c Value are inherited from \c M. 
-  ///\c Value must be comparable to \c 0 and the unary \c -
-  ///operator must be defined for it, of course.
-  template<typename M> 
+
+  /// Absolute value of a map
+
+  /// This \ref concepts::ReadMap "read-only map" returns the absolute
+  /// value of the values of the given map.
+  /// Its \c Key and \c Value are inherited from \c M.
+  /// \c Value must be comparable to \c 0 and the unary \c -
+  /// operator must be defined for it, of course.
+  ///
+  /// The simplest way of using this map is through the absMap()
+  /// function.
+  template<typename M>
   class AbsMap : public MapBase<typename M::Key, typename M::Value> {
-    const M& m;
+    const M &_m;
   public:
     typedef MapBase<typename M::Key, typename M::Value> Parent;
@@ -1004,206 +1287,223 @@
     typedef typename Parent::Value Value;
 
-    ///Constructor
-    AbsMap(const M &_m) : m(_m) {};
-    /// \e
-    Value operator[](Key k) const {
-      Value tmp = m[k]; 
+    /// Constructor
+    AbsMap(const M &m) : _m(m) {}
+    /// \e
+    Value operator[](const Key &k) const {
+      Value tmp = _m[k];
       return tmp >= 0 ? tmp : -tmp;
     }
 
   };
-  
-  ///Returns an \c AbsMap class
-
-  ///This function just returns an \c AbsMap class.
-  ///\relates AbsMap
-  template<typename M> 
+
+  /// Returns an \ref AbsMap class
+
+  /// This function just returns an \ref AbsMap class.
+  ///
+  /// For example, if \c m is a map with \c double values, then
+  /// <tt>absMap(m)[x]</tt> will be equal to <tt>m[x]</tt> if
+  /// it is positive or zero and <tt>-m[x]</tt> if <tt>m[x]</tt> is
+  /// negative.
+  ///
+  /// \relates AbsMap
+  template<typename M>
   inline AbsMap<M> absMap(const M &m) {
     return AbsMap<M>(m);
   }
 
-  ///Converts an STL style functor to a map
-
-  ///This \ref concepts::ReadMap "read only map" returns the value
-  ///of a given functor.
-  ///
-  ///Template parameters \c K and \c V will become its
-  ///\c Key and \c Value. 
-  ///In most cases they have to be given explicitly because a 
-  ///functor typically does not provide \c argument_type and 
-  ///\c result_type typedefs.
-  ///
-  ///Parameter \c F is the type of the used functor.
-  ///
-  ///\sa MapFunctor
-  template<typename F, 
-	   typename K = typename F::argument_type, 
-	   typename V = typename F::result_type> 
-  class FunctorMap : public MapBase<K, V> {
-    F f;
-  public:
-    typedef MapBase<K, V> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-    FunctorMap(const F &_f = F()) : f(_f) {}
-    /// \e
-    Value operator[](Key k) const { return f(k);}
-  };
+  /// @}
   
-  ///Returns a \c FunctorMap class
-
-  ///This function just returns a \c FunctorMap class.
-  ///
-  ///This function is specialized for adaptable binary function
-  ///classes and C++ functions.
-  ///
-  ///\relates FunctorMap
-  template<typename K, typename V, typename F> inline 
-  FunctorMap<F, K, V> functorMap(const F &f) {
-    return FunctorMap<F, K, V>(f);
-  }
-
-  template <typename F> inline 
-  FunctorMap<F, typename F::argument_type, typename F::result_type> 
-  functorMap(const F &f) {
-    return FunctorMap<F, typename F::argument_type, 
-      typename F::result_type>(f);
-  }
-
-  template <typename K, typename V> inline 
-  FunctorMap<V (*)(K), K, V> functorMap(V (*f)(K)) {
-    return FunctorMap<V (*)(K), K, V>(f);
-  }
-
-
-  ///Converts a map to an STL style (unary) functor
-
-  ///This class Converts a map to an STL style (unary) functor.
-  ///That is it provides an <tt>operator()</tt> to read its values.
-  ///
-  ///For the sake of convenience it also works as
-  ///a ususal \ref concepts::ReadMap "readable map",
-  ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
-  ///
-  ///\sa FunctorMap
-  template <typename M> 
-  class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
-    const M& m;
-  public:
-    typedef MapBase<typename M::Key, typename M::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    typedef typename M::Key argument_type;
-    typedef typename M::Value result_type;
-
-    ///Constructor
-    MapFunctor(const M &_m) : m(_m) {};
-    ///\e
-    Value operator()(Key k) const {return m[k];}
-    ///\e
-    Value operator[](Key k) const {return m[k];}
-  };
-  
-  ///Returns a \c MapFunctor class
-
-  ///This function just returns a \c MapFunctor class.
-  ///\relates MapFunctor
-  template<typename M> 
-  inline MapFunctor<M> mapFunctor(const M &m) {
-    return MapFunctor<M>(m);
-  }
-
-  ///Just readable version of \ref ForkWriteMap
-
-  ///This map has two \ref concepts::ReadMap "readable map"
-  ///parameters and each read request will be passed just to the
-  ///first map. This class is the just readable map type of \c ForkWriteMap.
-  ///
-  ///The \c Key and \c Value are inherited from \c M1.
-  ///The \c Key and \c Value of \c M2 must be convertible from those of \c M1.
-  ///
-  ///\sa ForkWriteMap
-  ///
-  /// \todo Why is it needed?
-  template<typename  M1, typename M2> 
-  class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
-    const M1& m1;
-    const M2& m2;
-  public:
-    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-    ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {};
-    /// \e
-    Value operator[](Key k) const {return m1[k];}
-  };
-
-
-  ///Applies all map setting operations to two maps
-
-  ///This map has two \ref concepts::WriteMap "writable map"
-  ///parameters and each write request will be passed to both of them.
-  ///If \c M1 is also \ref concepts::ReadMap "readable",
-  ///then the read operations will return the
-  ///corresponding values of \c M1.
-  ///
-  ///The \c Key and \c Value are inherited from \c M1.
-  ///The \c Key and \c Value of \c M2 must be convertible from those of \c M1.
-  ///
-  ///\sa ForkMap
-  template<typename  M1, typename M2> 
-  class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
-    M1& m1;
-    M2& m2;
-  public:
-    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
-    typedef typename Parent::Key Key;
-    typedef typename Parent::Value Value;
-
-    ///Constructor
-    ForkWriteMap(M1 &_m1, M2 &_m2) : m1(_m1), m2(_m2) {};
-    ///\e
-    Value operator[](Key k) const {return m1[k];}
-    ///\e
-    void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
-  };
-  
-  ///Returns a \c ForkMap class
-
-  ///This function just returns a \c ForkMap class.
-  ///\relates ForkMap
-  template <typename M1, typename M2> 
-  inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
-    return ForkMap<M1, M2>(m1,m2);
-  }
-
-  ///Returns a \c ForkWriteMap class
-
-  ///This function just returns a \c ForkWriteMap class.
-  ///\relates ForkWriteMap
-  template <typename M1, typename M2> 
-  inline ForkWriteMap<M1, M2> forkMap(M1 &m1, M2 &m2) {
-    return ForkWriteMap<M1, M2>(m1,m2);
-  }
-
-
-  
-  /* ************* BOOL MAPS ******************* */
-  
-  ///Logical 'not' of a map
-  
-  ///This bool \ref concepts::ReadMap "read only map" returns the 
-  ///logical negation of the value returned by the given map.
-  ///Its \c Key is inherited from \c M, its \c Value is \c bool.
-  ///
-  ///\sa NotWriteMap
-  template <typename M> 
+  // Logical maps and map adaptors:
+
+  /// \addtogroup maps
+  /// @{
+
+  /// Constant \c true map.
+
+  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
+  /// each key.
+  ///
+  /// Note that
+  /// \code
+  ///   TrueMap<K> tm;
+  /// \endcode
+  /// is equivalent to
+  /// \code
+  ///   ConstMap<K,bool> tm(true);
+  /// \endcode
+  ///
+  /// \sa FalseMap
+  /// \sa ConstMap
+  template <typename K>
+  class TrueMap : public MapBase<K, bool> {
+  public:
+    typedef MapBase<K, bool> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Gives back \c true.
+    Value operator[](const Key&) const { return true; }
+  };
+
+  /// Returns a \ref TrueMap class
+
+  /// This function just returns a \ref TrueMap class.
+  /// \relates TrueMap
+  template<typename K>
+  inline TrueMap<K> trueMap() {
+    return TrueMap<K>();
+  }
+
+
+  /// Constant \c false map.
+
+  /// This \ref concepts::ReadMap "read-only map" assigns \c false to
+  /// each key.
+  ///
+  /// Note that
+  /// \code
+  ///   FalseMap<K> fm;
+  /// \endcode
+  /// is equivalent to
+  /// \code
+  ///   ConstMap<K,bool> fm(false);
+  /// \endcode
+  ///
+  /// \sa TrueMap
+  /// \sa ConstMap
+  template <typename K>
+  class FalseMap : public MapBase<K, bool> {
+  public:
+    typedef MapBase<K, bool> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Gives back \c false.
+    Value operator[](const Key&) const { return false; }
+  };
+
+  /// Returns a \ref FalseMap class
+
+  /// This function just returns a \ref FalseMap class.
+  /// \relates FalseMap
+  template<typename K>
+  inline FalseMap<K> falseMap() {
+    return FalseMap<K>();
+  }
+
+  /// @}
+
+  /// \addtogroup map_adaptors
+  /// @{
+
+  /// Logical 'and' of two maps
+
+  /// This \ref concepts::ReadMap "read-only map" returns the logical
+  /// 'and' of the values of the two given maps.
+  /// Its \c Key type is inherited from \c M1 and its \c Value type is
+  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
+  ///
+  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   AndMap<M1,M2> am(m1,m2);
+  /// \endcode
+  /// <tt>am[x]</tt> will be equal to <tt>m1[x]&&m2[x]</tt>.
+  ///
+  /// The simplest way of using this map is through the andMap()
+  /// function.
+  ///
+  /// \sa OrMap
+  /// \sa NotMap, NotWriteMap
+  template<typename M1, typename M2>
+  class AndMap : public MapBase<typename M1::Key, bool> {
+    const M1 &_m1;
+    const M2 &_m2;
+  public:
+    typedef MapBase<typename M1::Key, bool> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+    AndMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m1[k]&&_m2[k]; }
+  };
+
+  /// Returns an \ref AndMap class
+
+  /// This function just returns an \ref AndMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are both maps with \c bool values,
+  /// then <tt>andMap(m1,m2)[x]</tt> will be equal to
+  /// <tt>m1[x]&&m2[x]</tt>.
+  ///
+  /// \relates AndMap
+  template<typename M1, typename M2>
+  inline AndMap<M1, M2> andMap(const M1 &m1, const M2 &m2) {
+    return AndMap<M1, M2>(m1,m2);
+  }
+
+
+  /// Logical 'or' of two maps
+
+  /// This \ref concepts::ReadMap "read-only map" returns the logical
+  /// 'or' of the values of the two given maps.
+  /// Its \c Key type is inherited from \c M1 and its \c Value type is
+  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
+  ///
+  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   OrMap<M1,M2> om(m1,m2);
+  /// \endcode
+  /// <tt>om[x]</tt> will be equal to <tt>m1[x]||m2[x]</tt>.
+  ///
+  /// The simplest way of using this map is through the orMap()
+  /// function.
+  ///
+  /// \sa AndMap
+  /// \sa NotMap, NotWriteMap
+  template<typename M1, typename M2>
+  class OrMap : public MapBase<typename M1::Key, bool> {
+    const M1 &_m1;
+    const M2 &_m2;
+  public:
+    typedef MapBase<typename M1::Key, bool> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+    OrMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m1[k]||_m2[k]; }
+  };
+
+  /// Returns an \ref OrMap class
+
+  /// This function just returns an \ref OrMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are both maps with \c bool values,
+  /// then <tt>orMap(m1,m2)[x]</tt> will be equal to
+  /// <tt>m1[x]||m2[x]</tt>.
+  ///
+  /// \relates OrMap
+  template<typename M1, typename M2>
+  inline OrMap<M1, M2> orMap(const M1 &m1, const M2 &m2) {
+    return OrMap<M1, M2>(m1,m2);
+  }
+
+
+  /// Logical 'not' of a map
+
+  /// This \ref concepts::ReadMap "read-only map" returns the logical
+  /// negation of the values of the given map.
+  /// Its \c Key is inherited from \c M and its \c Value is \c bool.
+  ///
+  /// The simplest way of using this map is through the notMap()
+  /// function.
+  ///
+  /// \sa NotWriteMap
+  template <typename M>
   class NotMap : public MapBase<typename M::Key, bool> {
-    const M& m;
+    const M &_m;
   public:
     typedef MapBase<typename M::Key, bool> Parent;
@@ -1212,20 +1512,24 @@
 
     /// Constructor
-    NotMap(const M &_m) : m(_m) {};
-    ///\e
-    Value operator[](Key k) const {return !m[k];}
-  };
-
-  ///Logical 'not' of a map (ReadWrie version)
-  
-  ///This bool \ref concepts::ReadWriteMap "read-write map" returns the 
-  ///logical negation of the value returned by the given map. When it is set,
-  ///the opposite value is set to the original map.
-  ///Its \c Key is inherited from \c M, its \c Value is \c bool.
-  ///
-  ///\sa NotMap
-  template <typename M> 
+    NotMap(const M &m) : _m(m) {}
+    /// \e
+    Value operator[](const Key &k) const { return !_m[k]; }
+  };
+
+  /// Logical 'not' of a map (read-write version)
+
+  /// This \ref concepts::ReadWriteMap "read-write map" returns the
+  /// logical negation of the values of the given map.
+  /// Its \c Key is inherited from \c M and its \c Value is \c bool.
+  /// It makes also possible to write the map. When a value is set,
+  /// the opposite value is set to the original map.
+  ///
+  /// The simplest way of using this map is through the notWriteMap()
+  /// function.
+  ///
+  /// \sa NotMap
+  template <typename M>
   class NotWriteMap : public MapBase<typename M::Key, bool> {
-    M& m;
+    M &_m;
   public:
     typedef MapBase<typename M::Key, bool> Parent;
@@ -1234,27 +1538,132 @@
 
     /// Constructor
-    NotWriteMap(M &_m) : m(_m) {};
-    ///\e
-    Value operator[](Key k) const {return !m[k];}
-    ///\e
-    void set(Key k, bool v) { m.set(k, !v); }
-  };
-  
-  ///Returns a \c NotMap class
-  
-  ///This function just returns a \c NotMap class.
-  ///\relates NotMap
-  template <typename M> 
+    NotWriteMap(M &m) : _m(m) {}
+    /// \e
+    Value operator[](const Key &k) const { return !_m[k]; }
+    /// \e
+    void set(const Key &k, bool v) { _m.set(k, !v); }
+  };
+
+  /// Returns a \ref NotMap class
+
+  /// This function just returns a \ref NotMap class.
+  ///
+  /// For example, if \c m is a map with \c bool values, then
+  /// <tt>notMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>.
+  ///
+  /// \relates NotMap
+  template <typename M>
   inline NotMap<M> notMap(const M &m) {
     return NotMap<M>(m);
   }
-  
-  ///Returns a \c NotWriteMap class
-  
-  ///This function just returns a \c NotWriteMap class.
-  ///\relates NotWriteMap
-  template <typename M> 
-  inline NotWriteMap<M> notMap(M &m) {
+
+  /// Returns a \ref NotWriteMap class
+
+  /// This function just returns a \ref NotWriteMap class.
+  ///
+  /// For example, if \c m is a map with \c bool values, then
+  /// <tt>notWriteMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>.
+  /// Moreover it makes also possible to write the map.
+  ///
+  /// \relates NotWriteMap
+  template <typename M>
+  inline NotWriteMap<M> notWriteMap(M &m) {
     return NotWriteMap<M>(m);
+  }
+
+
+  /// Combination of two maps using the \c == operator
+
+  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
+  /// the keys for which the corresponding values of the two maps are
+  /// equal.
+  /// Its \c Key type is inherited from \c M1 and its \c Value type is
+  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
+  ///
+  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   EqualMap<M1,M2> em(m1,m2);
+  /// \endcode
+  /// <tt>em[x]</tt> will be equal to <tt>m1[x]==m2[x]</tt>.
+  ///
+  /// The simplest way of using this map is through the equalMap()
+  /// function.
+  ///
+  /// \sa LessMap
+  template<typename M1, typename M2>
+  class EqualMap : public MapBase<typename M1::Key, bool> {
+    const M1 &_m1;
+    const M2 &_m2;
+  public:
+    typedef MapBase<typename M1::Key, bool> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+    EqualMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m1[k]==_m2[k]; }
+  };
+
+  /// Returns an \ref EqualMap class
+
+  /// This function just returns an \ref EqualMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are maps with keys and values of
+  /// the same type, then <tt>equalMap(m1,m2)[x]</tt> will be equal to
+  /// <tt>m1[x]==m2[x]</tt>.
+  ///
+  /// \relates EqualMap
+  template<typename M1, typename M2>
+  inline EqualMap<M1, M2> equalMap(const M1 &m1, const M2 &m2) {
+    return EqualMap<M1, M2>(m1,m2);
+  }
+
+
+  /// Combination of two maps using the \c < operator
+
+  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
+  /// the keys for which the corresponding value of the first map is
+  /// less then the value of the second map.
+  /// Its \c Key type is inherited from \c M1 and its \c Value type is
+  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
+  ///
+  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
+  /// \code
+  ///   LessMap<M1,M2> lm(m1,m2);
+  /// \endcode
+  /// <tt>lm[x]</tt> will be equal to <tt>m1[x]<m2[x]</tt>.
+  ///
+  /// The simplest way of using this map is through the lessMap()
+  /// function.
+  ///
+  /// \sa EqualMap
+  template<typename M1, typename M2>
+  class LessMap : public MapBase<typename M1::Key, bool> {
+    const M1 &_m1;
+    const M2 &_m2;
+  public:
+    typedef MapBase<typename M1::Key, bool> Parent;
+    typedef typename Parent::Key Key;
+    typedef typename Parent::Value Value;
+
+    /// Constructor
+    LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
+    /// \e
+    Value operator[](const Key &k) const { return _m1[k]<_m2[k]; }
+  };
+
+  /// Returns an \ref LessMap class
+
+  /// This function just returns an \ref LessMap class.
+  ///
+  /// For example, if \c m1 and \c m2 are maps with keys and values of
+  /// the same type, then <tt>lessMap(m1,m2)[x]</tt> will be equal to
+  /// <tt>m1[x]<m2[x]</tt>.
+  ///
+  /// \relates LessMap
+  template<typename M1, typename M2>
+  inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) {
+    return LessMap<M1, M2>(m1,m2);
   }
 
@@ -1277,5 +1686,5 @@
     template <typename _Iterator>
     struct IteratorTraits<_Iterator,
-      typename exists<typename _Iterator::container_type>::type> 
+      typename exists<typename _Iterator::container_type>::type>
     {
       typedef typename _Iterator::container_type::value_type Value;
@@ -1283,51 +1692,31 @@
 
   }
-  
 
   /// \brief Writable bool map for logging each \c true assigned element
   ///
-  /// A \ref concepts::ReadWriteMap "read-write" bool map for logging 
-  /// each \c true assigned element, i.e it copies all the keys set 
-  /// to \c true to the given iterator.
-  ///
-  /// \note The container of the iterator should contain space 
-  /// for each element.
-  ///
-  /// The following example shows how you can write the edges found by 
-  /// the \ref Prim algorithm directly to the standard output.
-  ///\code
-  /// typedef IdMap<Graph, Edge> EdgeIdMap;
-  /// EdgeIdMap edgeId(graph);
-  ///
-  /// typedef MapFunctor<EdgeIdMap> EdgeIdFunctor;
-  /// EdgeIdFunctor edgeIdFunctor(edgeId);
-  ///
-  /// StoreBoolMap<ostream_iterator<int>, EdgeIdFunctor> 
-  ///   writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor);
-  ///
-  /// prim(graph, cost, writerMap);
-  ///\endcode
-  ///
-  ///\sa BackInserterBoolMap 
-  ///\sa FrontInserterBoolMap 
-  ///\sa InserterBoolMap 
-  ///
-  ///\todo Revise the name of this class and the related ones.
-  template <typename _Iterator, 
-            typename _Functor =
-            _maps_bits::Identity<typename _maps_bits::
-                                 IteratorTraits<_Iterator>::Value> >
+  /// A \ref concepts::ReadWriteMap "read-write" bool map for logging
+  /// each \c true assigned element, i.e it copies subsequently each
+  /// keys set to \c true to the given iterator.
+  ///
+  /// \tparam It the type of the Iterator.
+  /// \tparam Ke the type of the map's Key. The default value should
+  /// work in most cases.
+  ///
+  /// \note The container of the iterator must contain enough space
+  /// for the elements. (Or it should be an inserter iterator).
+  ///
+  /// \todo Revise the name of this class and give an example code.
+  template <typename It,
+	    typename Ke=typename _maps_bits::IteratorTraits<It>::Value>
   class StoreBoolMap {
   public:
-    typedef _Iterator Iterator;
-
-    typedef typename _Functor::argument_type Key;
+    typedef It Iterator;
+
+    typedef Ke Key;
     typedef bool Value;
 
-    typedef _Functor Functor;
-
-    /// Constructor
-    StoreBoolMap(Iterator it, const Functor& functor = Functor()) 
-      : _begin(it), _end(it), _functor(functor) {}
+    /// Constructor
+    StoreBoolMap(Iterator it)
+      : _begin(it), _end(it) {}
 
     /// Gives back the given iterator set for the first key
@@ -1335,5 +1724,5 @@
       return _begin;
     }
- 
+
     /// Gives back the the 'after the last' iterator
     Iterator end() const {
@@ -1341,295 +1730,14 @@
     }
 
-    /// The \c set function of the map
+    /// The set function of the map
     void set(const Key& key, Value value) const {
       if (value) {
-	*_end++ = _functor(key);
+	*_end++ = key;
       }
     }
-    
+
   private:
     Iterator _begin;
     mutable Iterator _end;
-    Functor _functor;
-  };
-
-  /// \brief Writable bool map for logging each \c true assigned element in 
-  /// a back insertable container.
-  ///
-  /// Writable bool map for logging each \c true assigned element by pushing
-  /// them into a back insertable container.
-  /// It can be used to retrieve the items into a standard
-  /// container. The next example shows how you can store the
-  /// edges found by the Prim algorithm in a vector.
-  ///
-  ///\code
-  /// vector<Edge> span_tree_edges;
-  /// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges);
-  /// prim(graph, cost, inserter_map);
-  ///\endcode
-  ///
-  ///\sa StoreBoolMap
-  ///\sa FrontInserterBoolMap
-  ///\sa InserterBoolMap
-  template <typename Container,
-            typename Functor =
-            _maps_bits::Identity<typename Container::value_type> >
-  class BackInserterBoolMap {
-  public:
-    typedef typename Functor::argument_type Key;
-    typedef bool Value;
-
-    /// Constructor
-    BackInserterBoolMap(Container& _container, 
-                        const Functor& _functor = Functor()) 
-      : container(_container), functor(_functor) {}
-
-    /// The \c set function of the map
-    void set(const Key& key, Value value) {
-      if (value) {
-	container.push_back(functor(key));
-      }
-    }
-    
-  private:
-    Container& container;
-    Functor functor;
-  };
-
-  /// \brief Writable bool map for logging each \c true assigned element in 
-  /// a front insertable container.
-  ///
-  /// Writable bool map for logging each \c true assigned element by pushing
-  /// them into a front insertable container.
-  /// It can be used to retrieve the items into a standard
-  /// container. For example see \ref BackInserterBoolMap.
-  ///
-  ///\sa BackInserterBoolMap
-  ///\sa InserterBoolMap
-  template <typename Container,
-            typename Functor =
-            _maps_bits::Identity<typename Container::value_type> >
-  class FrontInserterBoolMap {
-  public:
-    typedef typename Functor::argument_type Key;
-    typedef bool Value;
-
-    /// Constructor
-    FrontInserterBoolMap(Container& _container,
-                         const Functor& _functor = Functor()) 
-      : container(_container), functor(_functor) {}
-
-    /// The \c set function of the map
-    void set(const Key& key, Value value) {
-      if (value) {
-	container.push_front(functor(key));
-      }
-    }
-    
-  private:
-    Container& container;    
-    Functor functor;
-  };
-
-  /// \brief Writable bool map for storing each \c true assigned element in 
-  /// an insertable container.
-  ///
-  /// Writable bool map for storing each \c true assigned element in an 
-  /// insertable container. It will insert all the keys set to \c true into
-  /// the container.
-  ///
-  /// For example, if you want to store the cut arcs of the strongly
-  /// connected components in a set you can use the next code:
-  ///
-  ///\code
-  /// set<Arc> cut_arcs;
-  /// InserterBoolMap<set<Arc> > inserter_map(cut_arcs);
-  /// stronglyConnectedCutArcs(digraph, cost, inserter_map);
-  ///\endcode
-  ///
-  ///\sa BackInserterBoolMap
-  ///\sa FrontInserterBoolMap
-  template <typename Container,
-            typename Functor =
-            _maps_bits::Identity<typename Container::value_type> >
-  class InserterBoolMap {
-  public:
-    typedef typename Container::value_type Key;
-    typedef bool Value;
-
-    /// Constructor with specified iterator
-    
-    /// Constructor with specified iterator.
-    /// \param _container The container for storing the elements.
-    /// \param _it The elements will be inserted before this iterator.
-    /// \param _functor The functor that is used when an element is stored.
-    InserterBoolMap(Container& _container, typename Container::iterator _it,
-                    const Functor& _functor = Functor()) 
-      : container(_container), it(_it), functor(_functor) {}
-
-    /// Constructor
-
-    /// Constructor without specified iterator.
-    /// The elements will be inserted before <tt>_container.end()</tt>.
-    /// \param _container The container for storing the elements.
-    /// \param _functor The functor that is used when an element is stored.
-    InserterBoolMap(Container& _container, const Functor& _functor = Functor())
-      : container(_container), it(_container.end()), functor(_functor) {}
-
-    /// The \c set function of the map
-    void set(const Key& key, Value value) {
-      if (value) {
-	it = container.insert(it, functor(key));
-        ++it;
-      }
-    }
-    
-  private:
-    Container& container;
-    typename Container::iterator it;
-    Functor functor;
-  };
-
-  /// \brief Writable bool map for filling each \c true assigned element with a 
-  /// given value.
-  ///
-  /// Writable bool map for filling each \c true assigned element with a 
-  /// given value. The value can set the container.
-  ///
-  /// The following code finds the connected components of a graph
-  /// and stores it in the \c comp map:
-  ///\code
-  /// typedef Graph::NodeMap<int> ComponentMap;
-  /// ComponentMap comp(graph);
-  /// typedef FillBoolMap<Graph::NodeMap<int> > ComponentFillerMap;
-  /// ComponentFillerMap filler(comp, 0);
-  ///
-  /// Dfs<Graph>::DefProcessedMap<ComponentFillerMap>::Create dfs(graph);
-  /// dfs.processedMap(filler);
-  /// dfs.init();
-  /// for (NodeIt it(graph); it != INVALID; ++it) {
-  ///   if (!dfs.reached(it)) {
-  ///     dfs.addSource(it);
-  ///     dfs.start();
-  ///     ++filler.fillValue();
-  ///   }
-  /// }
-  ///\endcode
-  template <typename Map>
-  class FillBoolMap {
-  public:
-    typedef typename Map::Key Key;
-    typedef bool Value;
-
-    /// Constructor
-    FillBoolMap(Map& _map, const typename Map::Value& _fill) 
-      : map(_map), fill(_fill) {}
-
-    /// Constructor
-    FillBoolMap(Map& _map) 
-      : map(_map), fill() {}
-
-    /// Gives back the current fill value
-    const typename Map::Value& fillValue() const {
-      return fill;
-    } 
-
-    /// Gives back the current fill value
-    typename Map::Value& fillValue() {
-      return fill;
-    } 
-
-    /// Sets the current fill value
-    void fillValue(const typename Map::Value& _fill) {
-      fill = _fill;
-    } 
-
-    /// The \c set function of the map
-    void set(const Key& key, Value value) {
-      if (value) {
-	map.set(key, fill);
-      }
-    }
-    
-  private:
-    Map& map;
-    typename Map::Value fill;
-  };
-
-
-  /// \brief Writable bool map for storing the sequence number of 
-  /// \c true assignments.  
-  /// 
-  /// Writable bool map that stores for each \c true assigned elements  
-  /// the sequence number of this setting.
-  /// It makes it easy to calculate the leaving
-  /// order of the nodes in the \c Dfs algorithm.
-  ///
-  ///\code
-  /// typedef Digraph::NodeMap<int> OrderMap;
-  /// OrderMap order(digraph);
-  /// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap;
-  /// OrderSetterMap setter(order);
-  /// Dfs<Digraph>::DefProcessedMap<OrderSetterMap>::Create dfs(digraph);
-  /// dfs.processedMap(setter);
-  /// dfs.init();
-  /// for (NodeIt it(digraph); it != INVALID; ++it) {
-  ///   if (!dfs.reached(it)) {
-  ///     dfs.addSource(it);
-  ///     dfs.start();
-  ///   }
-  /// }
-  ///\endcode
-  ///
-  /// The storing of the discovering order is more difficult because the
-  /// ReachedMap should be readable in the dfs algorithm but the setting
-  /// order map is not readable. Thus we must use the fork map:
-  ///
-  ///\code
-  /// typedef Digraph::NodeMap<int> OrderMap;
-  /// OrderMap order(digraph);
-  /// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap;
-  /// OrderSetterMap setter(order);
-  /// typedef Digraph::NodeMap<bool> StoreMap;
-  /// StoreMap store(digraph);
-  ///
-  /// typedef ForkWriteMap<StoreMap, OrderSetterMap> ReachedMap;
-  /// ReachedMap reached(store, setter);
-  ///
-  /// Dfs<Digraph>::DefReachedMap<ReachedMap>::Create dfs(digraph);
-  /// dfs.reachedMap(reached);
-  /// dfs.init();
-  /// for (NodeIt it(digraph); it != INVALID; ++it) {
-  ///   if (!dfs.reached(it)) {
-  ///     dfs.addSource(it);
-  ///     dfs.start();
-  ///   }
-  /// }
-  ///\endcode
-  template <typename Map>
-  class SettingOrderBoolMap {
-  public:
-    typedef typename Map::Key Key;
-    typedef bool Value;
-
-    /// Constructor
-    SettingOrderBoolMap(Map& _map) 
-      : map(_map), counter(0) {}
-
-    /// Number of set operations.
-    int num() const {
-      return counter;
-    }
-
-    /// The \c set function of the map
-    void set(const Key& key, Value value) {
-      if (value) {
-	map.set(key, counter++);
-      }
-    }
-    
-  private:
-    Map& map;
-    int counter;
   };
 
Index: lemon/path.h
===================================================================
--- lemon/path.h	(revision 100)
+++ lemon/path.h	(revision 100)
@@ -0,0 +1,1079 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+///\ingroup paths
+///\file
+///\brief Classes for representing paths in digraphs.
+///
+
+#ifndef LEMON_PATH_H
+#define LEMON_PATH_H
+
+#include <vector>
+#include <algorithm>
+
+#include <lemon/error.h>
+#include <lemon/bits/invalid.h>
+#include <lemon/concepts/path.h>
+
+namespace lemon {
+
+  /// \addtogroup paths
+  /// @{
+
+
+  /// \brief A structure for representing directed paths in a digraph.
+  ///
+  /// A structure for representing directed path in a digraph.
+  /// \param Digraph The digraph type in which the path is.
+  ///
+  /// In a sense, the path can be treated as a list of arcs. The
+  /// lemon path type stores just this list. As a consequence, it
+  /// cannot enumerate the nodes of the path and the source node of
+  /// a zero length path is undefined.
+  ///
+  /// This implementation is a back and front insertable and erasable
+  /// path type. It can be indexed in O(1) time. The front and back
+  /// insertion and erase is done in O(1) (amortized) time. The
+  /// implementation uses two vectors for storing the front and back
+  /// insertions.
+  template <typename _Digraph>
+  class Path {
+  public:
+
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+
+    /// \brief Default constructor
+    ///
+    /// Default constructor
+    Path() {}
+
+    /// \brief Template copy constructor
+    ///
+    /// This constuctor initializes the path from any other path type.
+    /// It simply makes a copy of the given path.
+    template <typename CPath>
+    Path(const CPath& cpath) {
+      copyPath(*this, cpath);
+    }
+
+    /// \brief Template copy assignment
+    ///
+    /// This operator makes a copy of a path of any other type.
+    template <typename CPath>
+    Path& operator=(const CPath& cpath) {
+      copyPath(*this, cpath);
+      return *this;
+    }
+
+    /// \brief Lemon style iterator for path arcs
+    ///
+    /// This class is used to iterate on the arcs of the paths.
+    class ArcIt {
+      friend class Path;
+    public:
+      /// \brief Default constructor
+      ArcIt() {}
+      /// \brief Invalid constructor
+      ArcIt(Invalid) : path(0), idx(-1) {}
+      /// \brief Initializate the iterator to the first arc of path
+      ArcIt(const Path &_path) 
+        : path(&_path), idx(_path.empty() ? -1 : 0) {}
+
+    private:
+
+      ArcIt(const Path &_path, int _idx) 
+        : path(&_path), idx(_idx) {}
+
+    public:
+
+      /// \brief Conversion to Arc
+      operator const Arc&() const {
+        return path->nth(idx);
+      }
+
+      /// \brief Next arc
+      ArcIt& operator++() { 
+        ++idx;
+        if (idx >= path->length()) idx = -1; 
+        return *this; 
+      }
+
+      /// \brief Comparison operator
+      bool operator==(const ArcIt& e) const { return idx==e.idx; }
+      /// \brief Comparison operator
+      bool operator!=(const ArcIt& e) const { return idx!=e.idx; }
+      /// \brief Comparison operator
+      bool operator<(const ArcIt& e) const { return idx<e.idx; }
+
+    private:
+      const Path *path;
+      int idx;
+    };
+
+    /// \brief Length of the path.
+    int length() const { return head.size() + tail.size(); }
+    /// \brief Return whether the path is empty.
+    bool empty() const { return head.empty() && tail.empty(); }
+
+    /// \brief Reset the path to an empty one.
+    void clear() { head.clear(); tail.clear(); }
+
+    /// \brief The nth arc.
+    ///
+    /// \pre n is in the [0..length() - 1] range
+    const Arc& nth(int n) const {
+      return n < int(head.size()) ? *(head.rbegin() + n) :
+        *(tail.begin() + (n - head.size()));
+    }
+
+    /// \brief Initialize arc iterator to point to the nth arc
+    ///
+    /// \pre n is in the [0..length() - 1] range
+    ArcIt nthIt(int n) const {
+      return ArcIt(*this, n);
+    }
+
+    /// \brief The first arc of the path
+    const Arc& front() const {
+      return head.empty() ? tail.front() : head.back();
+    }
+
+    /// \brief Add a new arc before the current path
+    void addFront(const Arc& arc) {
+      head.push_back(arc);
+    }
+
+    /// \brief Erase the first arc of the path
+    void eraseFront() {
+      if (!head.empty()) {
+        head.pop_back();
+      } else {
+        head.clear();
+        int halfsize = tail.size() / 2;
+        head.resize(halfsize);
+        std::copy(tail.begin() + 1, tail.begin() + halfsize + 1,
+                  head.rbegin());
+        std::copy(tail.begin() + halfsize + 1, tail.end(), tail.begin());
+        tail.resize(tail.size() - halfsize - 1);
+      }
+    }
+
+    /// \brief The last arc of the path
+    const Arc& back() const {
+      return tail.empty() ? head.front() : tail.back();
+    }
+
+    /// \brief Add a new arc behind the current path
+    void addBack(const Arc& arc) {
+      tail.push_back(arc);
+    }
+
+    /// \brief Erase the last arc of the path
+    void eraseBack() {
+      if (!tail.empty()) {
+        tail.pop_back();
+      } else {
+        int halfsize = head.size() / 2;
+        tail.resize(halfsize);
+        std::copy(head.begin() + 1, head.begin() + halfsize + 1,
+                  tail.rbegin());
+        std::copy(head.begin() + halfsize + 1, head.end(), head.begin());
+        head.resize(head.size() - halfsize - 1);
+      }
+    }
+
+    typedef True BuildTag;
+
+    template <typename CPath>
+    void build(const CPath& path) {
+      int len = path.length();
+      tail.reserve(len);
+      for (typename CPath::ArcIt it(path); it != INVALID; ++it) {
+        tail.push_back(it);
+      }
+    }
+
+    template <typename CPath>
+    void buildRev(const CPath& path) {
+      int len = path.length();
+      head.reserve(len);
+      for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
+        head.push_back(it);
+      }
+    }
+
+  protected:
+    typedef std::vector<Arc> Container;
+    Container head, tail;
+
+  };
+
+  /// \brief A structure for representing directed paths in a digraph.
+  ///
+  /// A structure for representing directed path in a digraph.
+  /// \param Digraph The digraph type in which the path is.
+  ///
+  /// In a sense, the path can be treated as a list of arcs. The
+  /// lemon path type stores just this list. As a consequence it
+  /// cannot enumerate the nodes in the path and the zero length paths
+  /// cannot store the source.
+  ///
+  /// This implementation is a just back insertable and erasable path
+  /// type. It can be indexed in O(1) time. The back insertion and
+  /// erasure is amortized O(1) time. This implementation is faster
+  /// then the \c Path type because it use just one vector for the
+  /// arcs.
+  template <typename _Digraph>
+  class SimplePath {
+  public:
+
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+
+    /// \brief Default constructor
+    ///
+    /// Default constructor
+    SimplePath() {}
+
+    /// \brief Template copy constructor
+    ///
+    /// This path can be initialized with any other path type. It just
+    /// makes a copy of the given path.
+    template <typename CPath>
+    SimplePath(const CPath& cpath) {
+      copyPath(*this, cpath);
+    }
+
+    /// \brief Template copy assignment
+    ///
+    /// This path can be initialized with any other path type. It just
+    /// makes a copy of the given path.
+    template <typename CPath>
+    SimplePath& operator=(const CPath& cpath) {
+      copyPath(*this, cpath);
+      return *this;
+    }
+
+    /// \brief Iterator class to iterate on the arcs of the paths
+    ///
+    /// This class is used to iterate on the arcs of the paths
+    ///
+    /// Of course it converts to Digraph::Arc
+    class ArcIt {
+      friend class SimplePath;
+    public:
+      /// Default constructor
+      ArcIt() {}
+      /// Invalid constructor
+      ArcIt(Invalid) : path(0), idx(-1) {}
+      /// \brief Initializate the constructor to the first arc of path
+      ArcIt(const SimplePath &_path) 
+        : path(&_path), idx(_path.empty() ? -1 : 0) {}
+
+    private:
+
+      /// Constructor with starting point
+      ArcIt(const SimplePath &_path, int _idx) 
+        : idx(_idx), path(&_path) {}
+
+    public:
+
+      ///Conversion to Digraph::Arc
+      operator const Arc&() const {
+        return path->nth(idx);
+      }
+
+      /// Next arc
+      ArcIt& operator++() { 
+        ++idx;
+        if (idx >= path->length()) idx = -1; 
+        return *this; 
+      }
+
+      /// Comparison operator
+      bool operator==(const ArcIt& e) const { return idx==e.idx; }
+      /// Comparison operator
+      bool operator!=(const ArcIt& e) const { return idx!=e.idx; }
+      /// Comparison operator
+      bool operator<(const ArcIt& e) const { return idx<e.idx; }
+
+    private:
+      const SimplePath *path;
+      int idx;
+    };
+
+    /// \brief Length of the path.
+    int length() const { return data.size(); }
+    /// \brief Return true if the path is empty.
+    bool empty() const { return data.empty(); }
+
+    /// \brief Reset the path to an empty one.
+    void clear() { data.clear(); }
+
+    /// \brief The nth arc.
+    ///
+    /// \pre n is in the [0..length() - 1] range
+    const Arc& nth(int n) const {
+      return data[n];
+    }
+
+    /// \brief  Initializes arc iterator to point to the nth arc.
+    ArcIt nthIt(int n) const {
+      return ArcIt(*this, n);
+    }
+
+    /// \brief The first arc of the path.
+    const Arc& front() const {
+      return data.front();
+    }
+
+    /// \brief The last arc of the path.
+    const Arc& back() const {
+      return data.back();
+    }
+
+    /// \brief Add a new arc behind the current path.
+    void addBack(const Arc& arc) {
+      data.push_back(arc);
+    }
+
+    /// \brief Erase the last arc of the path
+    void eraseBack() {
+      data.pop_back();
+    }
+
+    typedef True BuildTag;
+
+    template <typename CPath>
+    void build(const CPath& path) {
+      int len = path.length();
+      data.resize(len);
+      int index = 0;
+      for (typename CPath::ArcIt it(path); it != INVALID; ++it) {
+        data[index] = it;;
+        ++index;
+      }
+    }
+
+    template <typename CPath>
+    void buildRev(const CPath& path) {
+      int len = path.length();
+      data.resize(len);
+      int index = len;
+      for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
+        --index;
+        data[index] = it;;
+      }
+    }
+
+  protected:
+    typedef std::vector<Arc> Container;
+    Container data;
+
+  };
+
+  /// \brief A structure for representing directed paths in a digraph.
+  ///
+  /// A structure for representing directed path in a digraph.
+  /// \param Digraph The digraph type in which the path is.
+  ///
+  /// In a sense, the path can be treated as a list of arcs. The
+  /// lemon path type stores just this list. As a consequence it
+  /// cannot enumerate the nodes in the path and the zero length paths
+  /// cannot store the source.
+  ///
+  /// This implementation is a back and front insertable and erasable
+  /// path type. It can be indexed in O(k) time, where k is the rank
+  /// of the arc in the path. The length can be computed in O(n)
+  /// time. The front and back insertion and erasure is O(1) time
+  /// and it can be splited and spliced in O(1) time.
+  template <typename _Digraph>
+  class ListPath {
+  public:
+
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+
+  protected:
+
+    // the std::list<> is incompatible 
+    // hard to create invalid iterator
+    struct Node {
+      Arc arc;
+      Node *next, *prev;
+    };
+
+    Node *first, *last;
+
+    std::allocator<Node> alloc;
+
+  public:
+ 
+    /// \brief Default constructor
+    ///
+    /// Default constructor
+    ListPath() : first(0), last(0) {}
+
+    /// \brief Template copy constructor
+    ///
+    /// This path can be initialized with any other path type. It just
+    /// makes a copy of the given path.
+    template <typename CPath>
+    ListPath(const CPath& cpath) : first(0), last(0) {
+      copyPath(*this, cpath);
+    }
+
+    /// \brief Destructor of the path
+    ///
+    /// Destructor of the path
+    ~ListPath() {
+      clear();
+    }
+
+    /// \brief Template copy assignment
+    ///
+    /// This path can be initialized with any other path type. It just
+    /// makes a copy of the given path.
+    template <typename CPath>
+    ListPath& operator=(const CPath& cpath) {
+      copyPath(*this, cpath);
+      return *this;
+    }
+
+    /// \brief Iterator class to iterate on the arcs of the paths
+    ///
+    /// This class is used to iterate on the arcs of the paths
+    ///
+    /// Of course it converts to Digraph::Arc
+    class ArcIt {
+      friend class ListPath;
+    public:
+      /// Default constructor
+      ArcIt() {}
+      /// Invalid constructor
+      ArcIt(Invalid) : path(0), node(0) {}
+      /// \brief Initializate the constructor to the first arc of path
+      ArcIt(const ListPath &_path) 
+        : path(&_path), node(_path.first) {}
+
+    protected:
+
+      ArcIt(const ListPath &_path, Node *_node) 
+        : path(&_path), node(_node) {}
+
+
+    public:
+
+      ///Conversion to Digraph::Arc
+      operator const Arc&() const {
+        return node->arc;
+      }
+
+      /// Next arc
+      ArcIt& operator++() { 
+        node = node->next;
+        return *this; 
+      }
+
+      /// Comparison operator
+      bool operator==(const ArcIt& e) const { return node==e.node; }
+      /// Comparison operator
+      bool operator!=(const ArcIt& e) const { return node!=e.node; }
+      /// Comparison operator
+      bool operator<(const ArcIt& e) const { return node<e.node; }
+
+    private:
+      const ListPath *path;
+      Node *node;
+    };
+
+    /// \brief The nth arc.
+    ///
+    /// This function looks for the nth arc in O(n) time.
+    /// \pre n is in the [0..length() - 1] range
+    const Arc& nth(int n) const {
+      Node *node = first;
+      for (int i = 0; i < n; ++i) {
+        node = node->next;
+      }
+      return node->arc;
+    }
+
+    /// \brief Initializes arc iterator to point to the nth arc.
+    ArcIt nthIt(int n) const {
+      Node *node = first;
+      for (int i = 0; i < n; ++i) {
+        node = node->next;
+      }
+      return ArcIt(*this, node);
+    }
+
+    /// \brief Length of the path.
+    int length() const {
+      int len = 0;
+      Node *node = first;
+      while (node != 0) {
+        node = node->next;
+        ++len;
+      }
+      return len;
+    }
+
+    /// \brief Return true if the path is empty.
+    bool empty() const { return first == 0; }
+
+    /// \brief Reset the path to an empty one.
+    void clear() {
+      while (first != 0) {
+        last = first->next;
+        alloc.destroy(first);
+        alloc.deallocate(first, 1);
+        first = last;
+      }
+    }
+
+    /// \brief The first arc of the path
+    const Arc& front() const {
+      return first->arc;
+    }
+
+    /// \brief Add a new arc before the current path
+    void addFront(const Arc& arc) {
+      Node *node = alloc.allocate(1);
+      alloc.construct(node, Node());
+      node->prev = 0;
+      node->next = first;
+      node->arc = arc;
+      if (first) {
+        first->prev = node;
+        first = node;
+      } else {
+        first = last = node;
+      }
+    }
+
+    /// \brief Erase the first arc of the path
+    void eraseFront() {
+      Node *node = first;
+      first = first->next;
+      if (first) {
+        first->prev = 0;
+      } else {
+        last = 0;
+      }
+      alloc.destroy(node);
+      alloc.deallocate(node, 1);
+    }
+
+    /// \brief The last arc of the path.
+    const Arc& back() const {
+      return last->arc;
+    }
+
+    /// \brief Add a new arc behind the current path.
+    void addBack(const Arc& arc) {
+      Node *node = alloc.allocate(1);
+      alloc.construct(node, Node());
+      node->next = 0;
+      node->prev = last;
+      node->arc = arc;
+      if (last) {
+        last->next = node;
+        last = node;
+      } else {
+        last = first = node;
+      }
+    }
+
+    /// \brief Erase the last arc of the path
+    void eraseBack() {
+      Node *node = last;
+      last = last->prev;
+      if (last) {
+        last->next = 0;
+      } else {
+        first = 0;
+      }
+      alloc.destroy(node);
+      alloc.deallocate(node, 1);
+    }
+
+    /// \brief Splice a path to the back of the current path.
+    ///
+    /// It splices \c tpath to the back of the current path and \c
+    /// tpath becomes empty. The time complexity of this function is
+    /// O(1).
+    void spliceBack(ListPath& tpath) {
+      if (first) {
+        if (tpath.first) {
+          last->next = tpath.first;
+          tpath.first->prev = last;
+          last = tpath.last;
+        }
+      } else {
+        first = tpath.first;
+        last = tpath.last;
+      }
+      tpath.first = tpath.last = 0;
+    }
+
+    /// \brief Splice a path to the front of the current path.
+    ///
+    /// It splices \c tpath before the current path and \c tpath
+    /// becomes empty. The time complexity of this function
+    /// is O(1).
+    void spliceFront(ListPath& tpath) {
+      if (first) {
+        if (tpath.first) {
+          first->prev = tpath.last;
+          tpath.last->next = first;
+          first = tpath.first;
+        }
+      } else {
+        first = tpath.first;
+        last = tpath.last;
+      }
+      tpath.first = tpath.last = 0;
+    }
+
+    /// \brief Splice a path into the current path.
+    ///
+    /// It splices the \c tpath into the current path before the
+    /// position of \c it iterator and \c tpath becomes empty. The
+    /// time complexity of this function is O(1). If the \c it is
+    /// \c INVALID then it will splice behind the current path.
+    void splice(ArcIt it, ListPath& tpath) {
+      if (it.node) {
+        if (tpath.first) {
+          tpath.first->prev = it.node->prev;
+          if (it.node->prev) {
+            it.node->prev->next = tpath.first;
+          } else {
+            first = tpath.first;
+          }
+          it.node->prev = tpath.last;
+          tpath.last->next = it.node;
+        }
+      } else {
+        if (first) {
+          if (tpath.first) {
+            last->next = tpath.first;
+            tpath.first->prev = last;
+            last = tpath.last;
+          }
+        } else {
+          first = tpath.first;
+          last = tpath.last;
+        }
+      }
+      tpath.first = tpath.last = 0;
+    }
+
+    /// \brief Split the current path.
+    ///
+    /// It splits the current path into two parts. The part before
+    /// the iterator \c it will remain in the current path and the part
+    /// starting with
+    /// \c it will put into \c tpath. If \c tpath have arcs
+    /// before the operation they are removed first.  The time
+    /// complexity of this function is O(1) plus the the time of emtying
+    /// \c tpath. If \c it is \c INVALID then it just clears \c tpath
+    void split(ArcIt it, ListPath& tpath) {
+      tpath.clear();
+      if (it.node) {
+        tpath.first = it.node;
+        tpath.last = last;
+        if (it.node->prev) {
+          last = it.node->prev;
+          last->next = 0;
+        } else {
+          first = last = 0;
+        }
+        it.node->prev = 0;
+      }
+    }
+
+
+    typedef True BuildTag;
+
+    template <typename CPath>
+    void build(const CPath& path) {
+      for (typename CPath::ArcIt it(path); it != INVALID; ++it) {
+        addBack(it);
+      }
+    }
+
+    template <typename CPath>
+    void buildRev(const CPath& path) {
+      for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
+        addFront(it);
+      }
+    }
+
+  };
+
+  /// \brief A structure for representing directed paths in a digraph.
+  ///
+  /// A structure for representing directed path in a digraph.
+  /// \param Digraph The digraph type in which the path is.
+  ///
+  /// In a sense, the path can be treated as a list of arcs. The
+  /// lemon path type stores just this list. As a consequence it
+  /// cannot enumerate the nodes in the path and the source node of
+  /// a zero length path is undefined.
+  ///
+  /// This implementation is completly static, i.e. it can be copy constucted
+  /// or copy assigned from another path, but otherwise it cannot be
+  /// modified.
+  ///
+  /// Being the the most memory efficient path type in LEMON,
+  /// it is intented to be
+  /// used when you want to store a large number of paths.
+  template <typename _Digraph>
+  class StaticPath {
+  public:
+
+    typedef _Digraph Digraph;
+    typedef typename Digraph::Arc Arc;
+
+    /// \brief Default constructor
+    ///
+    /// Default constructor
+    StaticPath() : len(0), arcs(0) {}
+    
+    /// \brief Template copy constructor
+    ///
+    /// This path can be initialized from any other path type.
+    template <typename CPath>
+    StaticPath(const CPath& cpath) : arcs(0) {
+      copyPath(*this, cpath);
+    }
+
+    /// \brief Destructor of the path
+    ///
+    /// Destructor of the path
+    ~StaticPath() {
+      if (arcs) delete[] arcs;
+    }
+
+    /// \brief Template copy assignment
+    ///
+    /// This path can be made equal to any other path type. It simply
+    /// makes a copy of the given path.
+    template <typename CPath>
+    StaticPath& operator=(const CPath& cpath) {
+      copyPath(*this, cpath);
+      return *this;
+    }
+
+    /// \brief Iterator class to iterate on the arcs of the paths
+    ///
+    /// This class is used to iterate on the arcs of the paths
+    ///
+    /// Of course it converts to Digraph::Arc
+    class ArcIt {
+      friend class StaticPath;
+    public:
+      /// Default constructor
+      ArcIt() {}
+      /// Invalid constructor
+      ArcIt(Invalid) : path(0), idx(-1) {}
+      /// Initializate the constructor to the first arc of path
+      ArcIt(const StaticPath &_path) 
+        : path(&_path), idx(_path.empty() ? -1 : 0) {}
+
+    private:
+
+      /// Constructor with starting point
+      ArcIt(const StaticPath &_path, int _idx) 
+        : idx(_idx), path(&_path) {}
+
+    public:
+
+      ///Conversion to Digraph::Arc
+      operator const Arc&() const {
+        return path->nth(idx);
+      }
+
+      /// Next arc
+      ArcIt& operator++() { 
+        ++idx;
+        if (idx >= path->length()) idx = -1; 
+        return *this; 
+      }
+
+      /// Comparison operator
+      bool operator==(const ArcIt& e) const { return idx==e.idx; }
+      /// Comparison operator
+      bool operator!=(const ArcIt& e) const { return idx!=e.idx; }
+      /// Comparison operator
+      bool operator<(const ArcIt& e) const { return idx<e.idx; }
+
+    private:
+      const StaticPath *path;
+      int idx;
+    };
+
+    /// \brief The nth arc.
+    ///
+    /// \pre n is in the [0..length() - 1] range
+    const Arc& nth(int n) const {
+      return arcs[n];
+    }
+
+    /// \brief The arc iterator pointing to the nth arc.
+    ArcIt nthIt(int n) const {
+      return ArcIt(*this, n);
+    }
+
+    /// \brief The length of the path.
+    int length() const { return len; }
+
+    /// \brief Return true when the path is empty.
+    int empty() const { return len == 0; }
+
+    /// \break Erase all arcs in the digraph.
+    void clear() {
+      len = 0;
+      if (arcs) delete[] arcs;
+      arcs = 0;
+    }
+
+    /// \brief The first arc of the path.
+    const Arc& front() const {
+      return arcs[0];
+    }
+
+    /// \brief The last arc of the path.
+    const Arc& back() const {
+      return arcs[len - 1];
+    }
+
+
+    typedef True BuildTag;
+
+    template <typename CPath>
+    void build(const CPath& path) {
+      len = path.length();
+      arcs = new Arc[len];
+      int index = 0;
+      for (typename CPath::ArcIt it(path); it != INVALID; ++it) {
+        arcs[index] = it;
+        ++index;
+      }
+    }
+
+    template <typename CPath>
+    void buildRev(const CPath& path) {
+      len = path.length();
+      arcs = new Arc[len];
+      int index = len;
+      for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
+        --index;
+        arcs[index] = it;
+      }
+    }
+
+  private:
+    int len;
+    Arc* arcs;
+  };
+
+  ///////////////////////////////////////////////////////////////////////
+  // Additional utilities
+  ///////////////////////////////////////////////////////////////////////
+
+  namespace _path_bits {
+
+    template <typename Path, typename Enable = void>
+    struct RevTagIndicator {
+      static const bool value = false;
+    };
+
+    template <typename Digraph>
+    struct RevTagIndicator<
+      Digraph, 
+      typename enable_if<typename Digraph::RevTag, void>::type
+    > {
+      static const bool value = true;
+    };
+
+    template <typename Target, typename Source,
+              typename BuildEnable = void, typename RevEnable = void>
+    struct PathCopySelector {
+      static void copy(Target& target, const Source& source) {
+        target.clear();
+        for (typename Source::ArcIt it(source); it != INVALID; ++it) {
+          target.addBack(it);
+        }
+      }
+    };
+
+    template <typename Target, typename Source, typename BuildEnable>
+    struct PathCopySelector<
+      Target, Source, BuildEnable, 
+      typename enable_if<typename Source::RevPathTag, void>::type> {
+      static void copy(Target& target, const Source& source) {
+        target.clear();
+        for (typename Source::RevArcIt it(source); it != INVALID; ++it) {
+          target.addFront(it);
+        }
+      }
+    };
+
+    template <typename Target, typename Source, typename RevEnable>
+    struct PathCopySelector<
+      Target, Source, 
+      typename enable_if<typename Target::BuildTag, void>::type, RevEnable> {
+      static void copy(Target& target, const Source& source) {
+        target.clear();
+        target.build(source);
+      }
+    };
+
+    template <typename Target, typename Source>
+    struct PathCopySelector<
+      Target, Source, 
+      typename enable_if<typename Target::BuildTag, void>::type,
+      typename enable_if<typename Source::RevPathTag, void>::type> {
+      static void copy(Target& target, const Source& source) {
+        target.clear();
+        target.buildRev(source);
+      }
+    };
+
+  }
+
+
+  /// \brief Make a copy of a path.
+  ///
+  ///  This function makes a copy of a path.
+  template <typename Target, typename Source>
+  void copyPath(Target& target, const Source& source) {
+    checkConcept<concepts::PathDumper<typename Source::Digraph>, Source>();
+    _path_bits::PathCopySelector<Target, Source>::copy(target, source);
+  }
+
+  /// \brief Check the consistency of a path.
+  ///
+  /// This function checks that the target of each arc is the same
+  /// as the source of the next one. 
+  /// 
+  template <typename Digraph, typename Path>
+  bool checkPath(const Digraph& digraph, const Path& path) {
+    typename Path::ArcIt it(path);
+    if (it == INVALID) return true;
+    typename Digraph::Node node = digraph.target(it);
+    ++it;
+    while (it != INVALID) {
+      if (digraph.source(it) != node) return false;
+      node = digraph.target(it);
+      ++it;
+    }
+    return true;
+  }
+
+  /// \brief The source of a path
+  ///
+  /// This function returns the source of the given path.
+  template <typename Digraph, typename Path>
+  typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) {
+    return digraph.source(path.front());
+  }
+
+  /// \brief The target of a path
+  ///
+  /// This function returns the target of the given path.
+  template <typename Digraph, typename Path>
+  typename Digraph::Node pathTarget(const Digraph& digraph, const Path& path) {
+    return digraph.target(path.back());
+  }
+
+  /// \brief Class which helps to iterate through the nodes of a path
+  ///
+  /// In a sense, the path can be treated as a list of arcs. The
+  /// lemon path type stores only this list. As a consequence, it
+  /// cannot enumerate the nodes in the path and the zero length paths
+  /// cannot have a source node.
+  ///
+  /// This class implements the node iterator of a path structure. To
+  /// provide this feature, the underlying digraph should be passed to
+  /// the constructor of the iterator.
+  template <typename Path>
+  class PathNodeIt {
+  private:
+    const typename Path::Digraph *_digraph;
+    typename Path::ArcIt _it;
+    typename Path::Digraph::Node _nd;
+
+  public:
+
+    typedef typename Path::Digraph Digraph;
+    typedef typename Digraph::Node Node;
+    
+    /// Default constructor
+    PathNodeIt() {}
+    /// Invalid constructor
+    PathNodeIt(Invalid) 
+      : _digraph(0), _it(INVALID), _nd(INVALID) {}
+    /// Constructor
+    PathNodeIt(const Digraph& digraph, const Path& path) 
+      : _digraph(&digraph), _it(path) {
+      _nd = (_it != INVALID ? _digraph->source(_it) : INVALID);
+    }
+    /// Constructor
+    PathNodeIt(const Digraph& digraph, const Path& path, const Node& src) 
+      : _digraph(&digraph), _it(path), _nd(src) {}
+
+    ///Conversion to Digraph::Node
+    operator Node() const {
+      return _nd;
+    }
+
+    /// Next node
+    PathNodeIt& operator++() {
+      if (_it == INVALID) _nd = INVALID;
+      else {
+	_nd = _digraph->target(_it);
+	++_it;
+      }
+      return *this;
+    }
+
+    /// Comparison operator
+    bool operator==(const PathNodeIt& n) const { 
+      return _it == n._it && _nd == n._nd; 
+    }
+    /// Comparison operator
+    bool operator!=(const PathNodeIt& n) const { 
+      return _it != n._it || _nd != n._nd; 
+    }
+    /// Comparison operator
+    bool operator<(const PathNodeIt& n) const { 
+      return (_it < n._it && _nd != INVALID);
+    }
+    
+  };
+  
+  ///@}
+
+} // namespace lemon
+
+#endif // LEMON_PATH_H
Index: lemon/random.h
===================================================================
--- lemon/random.h	(revision 68)
+++ lemon/random.h	(revision 102)
@@ -576,4 +576,24 @@
     }
 
+    /// \brief Seeding random sequence
+    ///
+    /// Seeding the random sequence. The current number type will be
+    /// converted to the architecture word type.
+    template <typename Number>
+    void seed(Number seed) { 
+      _random_bits::Initializer<Number, Word>::init(core, seed);
+    }
+
+    /// \brief Seeding random sequence
+    ///
+    /// Seeding the random sequence. The given range should contain
+    /// any number type and the numbers will be converted to the
+    /// architecture word type.
+    template <typename Iterator>
+    void seed(Iterator begin, Iterator end) { 
+      typedef typename std::iterator_traits<Iterator>::value_type Number;
+      _random_bits::Initializer<Number, Word>::init(core, begin, end);
+    }
+
     /// \brief Returns a random real number from the range [0, 1)
     ///
@@ -804,4 +824,27 @@
     }  
       
+    /// Poisson distribution
+
+    /// This function generates a Poisson distribution random number with
+    /// parameter \c lambda.
+    /// 
+    /// The probability mass function of this distribusion is
+    /// \f[ \frac{e^{-\lambda}\lambda^k}{k!} \f]
+    /// \note The algorithm is taken from the book of Donald E. Knuth titled
+    /// ''Seminumerical Algorithms'' (1969). Its running time is linear in the
+    /// return value.
+    
+    int poisson(double lambda)
+    {
+      const double l = std::exp(-lambda);
+      int k=0;
+      double p = 1.0;
+      do {
+	k++;
+	p*=real<double>();
+      } while (p>=l);
+      return k-1;
+    }  
+      
     ///@}
     
Index: lemon/unionfind.h
===================================================================
--- lemon/unionfind.h	(revision 103)
+++ 	(revision )
@@ -1,1796 +1,0 @@
-/* -*- C++ -*-
- *
- * This file is a part of LEMON, a generic C++ optimization library
- *
- * Copyright (C) 2003-2008
- * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
- * (Egervary Research Group on Combinatorial Optimization, EGRES).
- *
- * Permission to use, modify and distribute this software is granted
- * provided that this copyright notice appears in all copies. For
- * precise terms see the accompanying LICENSE file.
- *
- * This software is provided "AS IS" with no warranty of any kind,
- * express or implied, and with no claim as to its suitability for any
- * purpose.
- *
- */
-
-#ifndef LEMON_UNION_FIND_H
-#define LEMON_UNION_FIND_H
-
-//!\ingroup auxdat
-//!\file
-//!\brief Union-Find data structures.
-//!
-
-#include <vector>
-#include <list>
-#include <utility>
-#include <algorithm>
-#include <functional>
-
-#include <lemon/bits/invalid.h>
-
-namespace lemon {
-
-  /// \ingroup auxdat
-  ///
-  /// \brief A \e Union-Find data structure implementation
-  ///
-  /// The class implements the \e Union-Find data structure. 
-  /// The union operation uses rank heuristic, while
-  /// the find operation uses path compression.
-  /// This is a very simple but efficient implementation, providing 
-  /// only four methods: join (union), find, insert and size.
-  /// For more features see the \ref UnionFindEnum class.
-  ///
-  /// It is primarily used in Kruskal algorithm for finding minimal
-  /// cost spanning tree in a graph.
-  /// \sa kruskal()
-  ///
-  /// \pre You need to add all the elements by the \ref insert()
-  /// method.  
-  template <typename _ItemIntMap>
-  class UnionFind {
-  public:
-
-    typedef _ItemIntMap ItemIntMap;
-    typedef typename ItemIntMap::Key Item;
-
-  private:
-    // If the items vector stores negative value for an item then
-    // that item is root item and it has -items[it] component size.
-    // Else the items[it] contains the index of the parent.
-    std::vector<int> items;
-    ItemIntMap& index;
-
-    bool rep(int idx) const {
-      return items[idx] < 0;
-    }
-
-    int repIndex(int idx) const {
-      int k = idx;
-      while (!rep(k)) {
-        k = items[k] ;
-      }
-      while (idx != k) {
-        int next = items[idx];
-        const_cast<int&>(items[idx]) = k;
-        idx = next;
-      }
-      return k;
-    }
-
-  public:
-
-    /// \brief Constructor
-    ///
-    /// Constructor of the UnionFind class. You should give an item to
-    /// integer map which will be used from the data structure. If you
-    /// modify directly this map that may cause segmentation fault,
-    /// invalid data structure, or infinite loop when you use again
-    /// the union-find.
-    UnionFind(ItemIntMap& m) : index(m) {}
-
-    /// \brief Returns the index of the element's component.
-    ///
-    /// The method returns the index of the element's component.
-    /// This is an integer between zero and the number of inserted elements.
-    ///
-    int find(const Item& a) {
-      return repIndex(index[a]);
-    }
-
-    /// \brief Clears the union-find data structure
-    ///
-    /// Erase each item from the data structure.
-    void clear() {
-      items.clear();
-    }
-
-    /// \brief Inserts a new element into the structure.
-    ///
-    /// This method inserts a new element into the data structure. 
-    ///
-    /// The method returns the index of the new component.
-    int insert(const Item& a) {
-      int n = items.size();
-      items.push_back(-1);
-      index.set(a,n);
-      return n;
-    }
-
-    /// \brief Joining the components of element \e a and element \e b.
-    ///
-    /// This is the \e union operation of the Union-Find structure. 
-    /// Joins the component of element \e a and component of
-    /// element \e b. If \e a and \e b are in the same component then
-    /// it returns false otherwise it returns true.
-    bool join(const Item& a, const Item& b) {
-      int ka = repIndex(index[a]);
-      int kb = repIndex(index[b]);
-
-      if ( ka == kb ) 
-	return false;
-
-      if (items[ka] < items[kb]) {
-	items[ka] += items[kb];
-	items[kb] = ka;
-      } else {
-	items[kb] += items[ka];
-	items[ka] = kb;
-      }
-      return true;
-    }
-
-    /// \brief Returns the size of the component of element \e a.
-    ///
-    /// Returns the size of the component of element \e a.
-    int size(const Item& a) {
-      int k = repIndex(index[a]);
-      return - items[k];
-    }
-
-  };
-
-  /// \ingroup auxdat
-  ///
-  /// \brief A \e Union-Find data structure implementation which
-  /// is able to enumerate the components.
-  ///
-  /// The class implements a \e Union-Find data structure
-  /// which is able to enumerate the components and the items in
-  /// a component. If you don't need this feature then perhaps it's
-  /// better to use the \ref UnionFind class which is more efficient.
-  ///
-  /// The union operation uses rank heuristic, while
-  /// the find operation uses path compression.
-  ///
-  /// \pre You need to add all the elements by the \ref insert()
-  /// method.
-  ///
-  template <typename _ItemIntMap>
-  class UnionFindEnum {
-  public:
-    
-    typedef _ItemIntMap ItemIntMap;
-    typedef typename ItemIntMap::Key Item;
-
-  private:
-    
-    ItemIntMap& index;
-
-    // If the parent stores negative value for an item then that item
-    // is root item and it has ~(items[it].parent) component id.  Else
-    // the items[it].parent contains the index of the parent.
-    //
-    // The \c next and \c prev provides the double-linked
-    // cyclic list of one component's items.
-    struct ItemT {
-      int parent;
-      Item item;
-
-      int next, prev;
-    };
-
-    std::vector<ItemT> items;
-    int firstFreeItem;
-
-    struct ClassT {
-      int size;
-      int firstItem;
-      int next, prev;
-    };
-    
-    std::vector<ClassT> classes;
-    int firstClass, firstFreeClass;
-
-    int newClass() {
-      if (firstFreeClass == -1) {
-	int cdx = classes.size();
-	classes.push_back(ClassT());
-	return cdx;
-      } else {
-	int cdx = firstFreeClass;
-	firstFreeClass = classes[firstFreeClass].next;
-	return cdx;
-      }
-    }
-
-    int newItem() {
-      if (firstFreeItem == -1) {
-	int idx = items.size();
-	items.push_back(ItemT());
-	return idx;
-      } else {
-	int idx = firstFreeItem;
-	firstFreeItem = items[firstFreeItem].next;
-	return idx;
-      }
-    }
-
-
-    bool rep(int idx) const {
-      return items[idx].parent < 0;
-    }
-
-    int repIndex(int idx) const {
-      int k = idx;
-      while (!rep(k)) {
-        k = items[k].parent;
-      }
-      while (idx != k) {
-        int next = items[idx].parent;
-        const_cast<int&>(items[idx].parent) = k;
-        idx = next;
-      }
-      return k;
-    }
-
-    int classIndex(int idx) const {
-      return ~(items[repIndex(idx)].parent);
-    }
-
-    void singletonItem(int idx) {
-      items[idx].next = idx;
-      items[idx].prev = idx;
-    }
-
-    void laceItem(int idx, int rdx) {
-      items[idx].prev = rdx;
-      items[idx].next = items[rdx].next;
-      items[items[rdx].next].prev = idx;
-      items[rdx].next = idx;
-    }
-
-    void unlaceItem(int idx) {
-      items[items[idx].prev].next = items[idx].next;
-      items[items[idx].next].prev = items[idx].prev;
-      
-      items[idx].next = firstFreeItem;
-      firstFreeItem = idx;
-    }
-
-    void spliceItems(int ak, int bk) {
-      items[items[ak].prev].next = bk;
-      items[items[bk].prev].next = ak;
-      int tmp = items[ak].prev;
-      items[ak].prev = items[bk].prev;
-      items[bk].prev = tmp;
-        
-    }
-
-    void laceClass(int cls) {
-      if (firstClass != -1) {
-        classes[firstClass].prev = cls;
-      }
-      classes[cls].next = firstClass;
-      classes[cls].prev = -1;
-      firstClass = cls;
-    } 
-
-    void unlaceClass(int cls) {
-      if (classes[cls].prev != -1) {
-        classes[classes[cls].prev].next = classes[cls].next;
-      } else {
-        firstClass = classes[cls].next;
-      }
-      if (classes[cls].next != -1) {
-        classes[classes[cls].next].prev = classes[cls].prev;
-      }
-      
-      classes[cls].next = firstFreeClass;
-      firstFreeClass = cls;
-    } 
-
-  public:
-
-    UnionFindEnum(ItemIntMap& _index) 
-      : index(_index), items(), firstFreeItem(-1), 
-	firstClass(-1), firstFreeClass(-1) {}
-    
-    /// \brief Inserts the given element into a new component.
-    ///
-    /// This method creates a new component consisting only of the
-    /// given element.
-    ///
-    int insert(const Item& item) {
-      int idx = newItem();
-
-      index.set(item, idx);
-
-      singletonItem(idx);
-      items[idx].item = item;
-
-      int cdx = newClass();
-
-      items[idx].parent = ~cdx;
-
-      laceClass(cdx);
-      classes[cdx].size = 1;
-      classes[cdx].firstItem = idx;
-
-      firstClass = cdx;
-      
-      return cdx;
-    }
-
-    /// \brief Inserts the given element into the component of the others.
-    ///
-    /// This methods inserts the element \e a into the component of the
-    /// element \e comp. 
-    void insert(const Item& item, int cls) {
-      int rdx = classes[cls].firstItem;
-      int idx = newItem();
-
-      index.set(item, idx);
-
-      laceItem(idx, rdx);
-
-      items[idx].item = item;
-      items[idx].parent = rdx;
-
-      ++classes[~(items[rdx].parent)].size;
-    }
-
-    /// \brief Clears the union-find data structure
-    ///
-    /// Erase each item from the data structure.
-    void clear() {
-      items.clear();
-      firstClass = -1;
-      firstFreeItem = -1;
-    }
-
-    /// \brief Finds the component of the given element.
-    ///
-    /// The method returns the component id of the given element.
-    int find(const Item &item) const {
-      return ~(items[repIndex(index[item])].parent);
-    }
-
-    /// \brief Joining the component of element \e a and element \e b.
-    ///
-    /// This is the \e union operation of the Union-Find structure. 
-    /// Joins the component of element \e a and component of
-    /// element \e b. If \e a and \e b are in the same component then
-    /// returns -1 else returns the remaining class.
-    int join(const Item& a, const Item& b) {
-
-      int ak = repIndex(index[a]);
-      int bk = repIndex(index[b]);
-
-      if (ak == bk) {
-	return -1;
-      }
-
-      int acx = ~(items[ak].parent);
-      int bcx = ~(items[bk].parent);
-
-      int rcx;
-
-      if (classes[acx].size > classes[bcx].size) {
-	classes[acx].size += classes[bcx].size;
-	items[bk].parent = ak;
-        unlaceClass(bcx);
-	rcx = acx;
-      } else {
-	classes[bcx].size += classes[acx].size;
-	items[ak].parent = bk;
-        unlaceClass(acx);
-	rcx = bcx;
-      }
-      spliceItems(ak, bk);
-
-      return rcx;
-    }
-
-    /// \brief Returns the size of the class.
-    ///
-    /// Returns the size of the class.
-    int size(int cls) const {
-      return classes[cls].size;
-    }
-
-    /// \brief Splits up the component. 
-    ///
-    /// Splitting the component into singleton components (component
-    /// of size one).
-    void split(int cls) {
-      int fdx = classes[cls].firstItem;
-      int idx = items[fdx].next;
-      while (idx != fdx) {
-        int next = items[idx].next;
-
-	singletonItem(idx);
-
-	int cdx = newClass();        
-        items[idx].parent = ~cdx;
-
-	laceClass(cdx);
-	classes[cdx].size = 1;
-	classes[cdx].firstItem = idx;
-        
-        idx = next;
-      }
-
-      items[idx].prev = idx;
-      items[idx].next = idx;
-
-      classes[~(items[idx].parent)].size = 1;
-      
-    }
-
-    /// \brief Removes the given element from the structure.
-    ///
-    /// Removes the element from its component and if the component becomes
-    /// empty then removes that component from the component list.
-    ///
-    /// \warning It is an error to remove an element which is not in
-    /// the structure.
-    /// \warning This running time of this operation is proportional to the
-    /// number of the items in this class.
-    void erase(const Item& item) {
-      int idx = index[item];
-      int fdx = items[idx].next;
-
-      int cdx = classIndex(idx);
-      if (idx == fdx) {
-	unlaceClass(cdx);
-	items[idx].next = firstFreeItem;
-	firstFreeItem = idx;
-	return;
-      } else {
-	classes[cdx].firstItem = fdx;
-	--classes[cdx].size;
-	items[fdx].parent = ~cdx;
-
-	unlaceItem(idx);
-	idx = items[fdx].next;
-	while (idx != fdx) {
-	  items[idx].parent = fdx;
-	  idx = items[idx].next;
-	}
-          
-      }
-
-    }
-
-    /// \brief Gives back a representant item of the component.
-    ///
-    /// Gives back a representant item of the component.
-    Item item(int cls) const {
-      return items[classes[cls].firstItem].item;
-    }
-
-    /// \brief Removes the component of the given element from the structure.
-    ///
-    /// Removes the component of the given element from the structure.
-    ///
-    /// \warning It is an error to give an element which is not in the
-    /// structure.
-    void eraseClass(int cls) {
-      int fdx = classes[cls].firstItem;
-      unlaceClass(cls);
-      items[items[fdx].prev].next = firstFreeItem;
-      firstFreeItem = fdx;
-    }
-
-    /// \brief Lemon style iterator for the representant items.
-    ///
-    /// ClassIt is a lemon style iterator for the components. It iterates
-    /// on the ids of the classes.
-    class ClassIt {
-    public:
-      /// \brief Constructor of the iterator
-      ///
-      /// Constructor of the iterator
-      ClassIt(const UnionFindEnum& ufe) : unionFind(&ufe) {
-        cdx = unionFind->firstClass;
-      }
-
-      /// \brief Constructor to get invalid iterator
-      ///
-      /// Constructor to get invalid iterator
-      ClassIt(Invalid) : unionFind(0), cdx(-1) {}
-      
-      /// \brief Increment operator
-      ///
-      /// It steps to the next representant item.
-      ClassIt& operator++() {
-        cdx = unionFind->classes[cdx].next;
-        return *this;
-      }
-      
-      /// \brief Conversion operator
-      ///
-      /// It converts the iterator to the current representant item.
-      operator int() const {
-        return cdx;
-      }
-
-      /// \brief Equality operator
-      ///
-      /// Equality operator
-      bool operator==(const ClassIt& i) { 
-        return i.cdx == cdx;
-      }
-
-      /// \brief Inequality operator
-      ///
-      /// Inequality operator
-      bool operator!=(const ClassIt& i) { 
-        return i.cdx != cdx;
-      }
-      
-    private:
-      const UnionFindEnum* unionFind;
-      int cdx;
-    };
-
-    /// \brief Lemon style iterator for the items of a component.
-    ///
-    /// ClassIt is a lemon style iterator for the components. It iterates
-    /// on the items of a class. By example if you want to iterate on
-    /// each items of each classes then you may write the next code.
-    ///\code
-    /// for (ClassIt cit(ufe); cit != INVALID; ++cit) {
-    ///   std::cout << "Class: ";
-    ///   for (ItemIt iit(ufe, cit); iit != INVALID; ++iit) {
-    ///     std::cout << toString(iit) << ' ' << std::endl;
-    ///   }
-    ///   std::cout << std::endl;
-    /// }
-    ///\endcode
-    class ItemIt {
-    public:
-      /// \brief Constructor of the iterator
-      ///
-      /// Constructor of the iterator. The iterator iterates
-      /// on the class of the \c item.
-      ItemIt(const UnionFindEnum& ufe, int cls) : unionFind(&ufe) {
-        fdx = idx = unionFind->classes[cls].firstItem;
-      }
-
-      /// \brief Constructor to get invalid iterator
-      ///
-      /// Constructor to get invalid iterator
-      ItemIt(Invalid) : unionFind(0), idx(-1) {}
-      
-      /// \brief Increment operator
-      ///
-      /// It steps to the next item in the class.
-      ItemIt& operator++() {
-        idx = unionFind->items[idx].next;
-        if (idx == fdx) idx = -1;
-        return *this;
-      }
-      
-      /// \brief Conversion operator
-      ///
-      /// It converts the iterator to the current item.
-      operator const Item&() const {
-        return unionFind->items[idx].item;
-      }
-
-      /// \brief Equality operator
-      ///
-      /// Equality operator
-      bool operator==(const ItemIt& i) { 
-        return i.idx == idx;
-      }
-
-      /// \brief Inequality operator
-      ///
-      /// Inequality operator
-      bool operator!=(const ItemIt& i) { 
-        return i.idx != idx;
-      }
-      
-    private:
-      const UnionFindEnum* unionFind;
-      int idx, fdx;
-    };
-
-  };
-
-  /// \ingroup auxdat
-  ///
-  /// \brief A \e Extend-Find data structure implementation which
-  /// is able to enumerate the components.
-  ///
-  /// The class implements an \e Extend-Find data structure which is
-  /// able to enumerate the components and the items in a
-  /// component. The data structure is a simplification of the
-  /// Union-Find structure, and it does not allow to merge two components.
-  ///
-  /// \pre You need to add all the elements by the \ref insert()
-  /// method.
-  template <typename _ItemIntMap>
-  class ExtendFindEnum {
-  public:
-    
-    typedef _ItemIntMap ItemIntMap;
-    typedef typename ItemIntMap::Key Item;
-
-  private:
-    
-    ItemIntMap& index;
-
-    struct ItemT {
-      int cls;
-      Item item;
-      int next, prev;
-    };
-
-    std::vector<ItemT> items;
-    int firstFreeItem;
-
-    struct ClassT {
-      int firstItem;
-      int next, prev;
-    };
-
-    std::vector<ClassT> classes;
-
-    int firstClass, firstFreeClass;
-
-    int newClass() {
-      if (firstFreeClass != -1) {
-	int cdx = firstFreeClass;
-	firstFreeClass = classes[cdx].next;
-	return cdx;
-      } else {
-	classes.push_back(ClassT());
-	return classes.size() - 1;
-      }
-    }
-
-    int newItem() {
-      if (firstFreeItem != -1) {
-	int idx = firstFreeItem;
-	firstFreeItem = items[idx].next;
-	return idx;
-      } else {
-	items.push_back(ItemT());
-	return items.size() - 1;
-      }
-    }
-
-  public:
-
-    /// \brief Constructor
-    ExtendFindEnum(ItemIntMap& _index) 
-      : index(_index), items(), firstFreeItem(-1), 
-	classes(), firstClass(-1), firstFreeClass(-1) {}
-    
-    /// \brief Inserts the given element into a new component.
-    ///
-    /// This method creates a new component consisting only of the
-    /// given element.
-    int insert(const Item& item) {
-      int cdx = newClass();
-      classes[cdx].prev = -1;
-      classes[cdx].next = firstClass;
-      if (firstClass != -1) {
-	classes[firstClass].prev = cdx;
-      }
-      firstClass = cdx;
-      
-      int idx = newItem();
-      items[idx].item = item;
-      items[idx].cls = cdx;
-      items[idx].prev = idx;
-      items[idx].next = idx;
-
-      classes[cdx].firstItem = idx;
-
-      index.set(item, idx);
-      
-      return cdx;
-    }
-
-    /// \brief Inserts the given element into the given component.
-    ///
-    /// This methods inserts the element \e item a into the \e cls class.
-    void insert(const Item& item, int cls) {
-      int idx = newItem();
-      int rdx = classes[cls].firstItem;
-      items[idx].item = item;
-      items[idx].cls = cls;
-
-      items[idx].prev = rdx;
-      items[idx].next = items[rdx].next;
-      items[items[rdx].next].prev = idx;
-      items[rdx].next = idx;
-
-      index.set(item, idx);
-    }
-
-    /// \brief Clears the union-find data structure
-    ///
-    /// Erase each item from the data structure.
-    void clear() {
-      items.clear();
-      classes.clear;
-      firstClass = firstFreeClass = firstFreeItem = -1;
-    }
-
-    /// \brief Gives back the class of the \e item.
-    ///
-    /// Gives back the class of the \e item.
-    int find(const Item &item) const {
-      return items[index[item]].cls;
-    }
-
-    /// \brief Gives back a representant item of the component.
-    ///
-    /// Gives back a representant item of the component.
-    Item item(int cls) const {
-      return items[classes[cls].firstItem].item;
-    }
-    
-    /// \brief Removes the given element from the structure.
-    ///
-    /// Removes the element from its component and if the component becomes
-    /// empty then removes that component from the component list.
-    ///
-    /// \warning It is an error to remove an element which is not in
-    /// the structure.
-    void erase(const Item &item) {
-      int idx = index[item];
-      int cdx = items[idx].cls;
-      
-      if (idx == items[idx].next) {
-	if (classes[cdx].prev != -1) {
-	  classes[classes[cdx].prev].next = classes[cdx].next; 
-	} else {
-	  firstClass = classes[cdx].next;
-	}
-	if (classes[cdx].next != -1) {
-	  classes[classes[cdx].next].prev = classes[cdx].prev; 
-	}
-	classes[cdx].next = firstFreeClass;
-	firstFreeClass = cdx;
-      } else {
-	classes[cdx].firstItem = items[idx].next;
-	items[items[idx].next].prev = items[idx].prev;
-	items[items[idx].prev].next = items[idx].next;
-      }
-      items[idx].next = firstFreeItem;
-      firstFreeItem = idx;
-	
-    }    
-
-    
-    /// \brief Removes the component of the given element from the structure.
-    ///
-    /// Removes the component of the given element from the structure.
-    ///
-    /// \warning It is an error to give an element which is not in the
-    /// structure.
-    void eraseClass(int cdx) {
-      int idx = classes[cdx].firstItem;
-      items[items[idx].prev].next = firstFreeItem;
-      firstFreeItem = idx;
-
-      if (classes[cdx].prev != -1) {
-	classes[classes[cdx].prev].next = classes[cdx].next; 
-      } else {
-	firstClass = classes[cdx].next;
-      }
-      if (classes[cdx].next != -1) {
-	classes[classes[cdx].next].prev = classes[cdx].prev; 
-      }
-      classes[cdx].next = firstFreeClass;
-      firstFreeClass = cdx;
-    }
-
-    /// \brief Lemon style iterator for the classes.
-    ///
-    /// ClassIt is a lemon style iterator for the components. It iterates
-    /// on the ids of classes.
-    class ClassIt {
-    public:
-      /// \brief Constructor of the iterator
-      ///
-      /// Constructor of the iterator
-      ClassIt(const ExtendFindEnum& ufe) : extendFind(&ufe) {
-        cdx = extendFind->firstClass;
-      }
-
-      /// \brief Constructor to get invalid iterator
-      ///
-      /// Constructor to get invalid iterator
-      ClassIt(Invalid) : extendFind(0), cdx(-1) {}
-      
-      /// \brief Increment operator
-      ///
-      /// It steps to the next representant item.
-      ClassIt& operator++() {
-        cdx = extendFind->classes[cdx].next;
-        return *this;
-      }
-      
-      /// \brief Conversion operator
-      ///
-      /// It converts the iterator to the current class id.
-      operator int() const {
-        return cdx;
-      }
-
-      /// \brief Equality operator
-      ///
-      /// Equality operator
-      bool operator==(const ClassIt& i) { 
-        return i.cdx == cdx;
-      }
-
-      /// \brief Inequality operator
-      ///
-      /// Inequality operator
-      bool operator!=(const ClassIt& i) { 
-        return i.cdx != cdx;
-      }
-      
-    private:
-      const ExtendFindEnum* extendFind;
-      int cdx;
-    };
-
-    /// \brief Lemon style iterator for the items of a component.
-    ///
-    /// ClassIt is a lemon style iterator for the components. It iterates
-    /// on the items of a class. By example if you want to iterate on
-    /// each items of each classes then you may write the next code.
-    ///\code
-    /// for (ClassIt cit(ufe); cit != INVALID; ++cit) {
-    ///   std::cout << "Class: ";
-    ///   for (ItemIt iit(ufe, cit); iit != INVALID; ++iit) {
-    ///     std::cout << toString(iit) << ' ' << std::endl;
-    ///   }
-    ///   std::cout << std::endl;
-    /// }
-    ///\endcode
-    class ItemIt {
-    public:
-      /// \brief Constructor of the iterator
-      ///
-      /// Constructor of the iterator. The iterator iterates
-      /// on the class of the \c item.
-      ItemIt(const ExtendFindEnum& ufe, int cls) : extendFind(&ufe) {
-        fdx = idx = extendFind->classes[cls].firstItem;
-      }
-
-      /// \brief Constructor to get invalid iterator
-      ///
-      /// Constructor to get invalid iterator
-      ItemIt(Invalid) : extendFind(0), idx(-1) {}
-      
-      /// \brief Increment operator
-      ///
-      /// It steps to the next item in the class.
-      ItemIt& operator++() {
-        idx = extendFind->items[idx].next;
-	if (fdx == idx) idx = -1;
-        return *this;
-      }
-      
-      /// \brief Conversion operator
-      ///
-      /// It converts the iterator to the current item.
-      operator const Item&() const {
-        return extendFind->items[idx].item;
-      }
-
-      /// \brief Equality operator
-      ///
-      /// Equality operator
-      bool operator==(const ItemIt& i) { 
-        return i.idx == idx;
-      }
-
-      /// \brief Inequality operator
-      ///
-      /// Inequality operator
-      bool operator!=(const ItemIt& i) { 
-        return i.idx != idx;
-      }
-      
-    private:
-      const ExtendFindEnum* extendFind;
-      int idx, fdx;
-    };
-
-  };
-
-  /// \ingroup auxdat
-  ///
-  /// \brief A \e Union-Find data structure implementation which
-  /// is able to store a priority for each item and retrieve the minimum of
-  /// each class.
-  ///
-  /// A \e Union-Find data structure implementation which is able to
-  /// store a priority for each item and retrieve the minimum of each
-  /// class. In addition, it supports the joining and splitting the
-  /// components. If you don't need this feature then you makes
-  /// better to use the \ref UnionFind class which is more efficient.
-  ///
-  /// The union-find data strcuture based on a (2, 16)-tree with a
-  /// tournament minimum selection on the internal nodes. The insert
-  /// operation takes O(1), the find, set, decrease and increase takes
-  /// O(log(n)), where n is the number of nodes in the current
-  /// component.  The complexity of join and split is O(log(n)*k),
-  /// where n is the sum of the number of the nodes and k is the
-  /// number of joined components or the number of the components
-  /// after the split.
-  ///
-  /// \pre You need to add all the elements by the \ref insert()
-  /// method.
-  ///
-  template <typename _Value, typename _ItemIntMap, 
-            typename _Comp = std::less<_Value> >
-  class HeapUnionFind {
-  public:
-    
-    typedef _Value Value;
-    typedef typename _ItemIntMap::Key Item;
-
-    typedef _ItemIntMap ItemIntMap;
-
-    typedef _Comp Comp;
-
-  private:
-
-    static const int cmax = 16;
-
-    ItemIntMap& index;
-
-    struct ClassNode {
-      int parent;
-      int depth;
-
-      int left, right;
-      int next, prev;
-    };
-
-    int first_class;
-    int first_free_class;
-    std::vector<ClassNode> classes;
-
-    int newClass() {
-      if (first_free_class < 0) {
-        int id = classes.size();
-        classes.push_back(ClassNode());
-        return id;
-      } else {
-        int id = first_free_class;
-        first_free_class = classes[id].next;
-        return id;
-      }
-    }
-
-    void deleteClass(int id) {
-      classes[id].next = first_free_class;
-      first_free_class = id;
-    }
-
-    struct ItemNode {
-      int parent;
-      Item item;
-      Value prio;
-      int next, prev;
-      int left, right;
-      int size;
-    };
-
-    int first_free_node;
-    std::vector<ItemNode> nodes;
-
-    int newNode() {
-      if (first_free_node < 0) {
-        int id = nodes.size();
-        nodes.push_back(ItemNode());
-        return id;
-      } else {
-        int id = first_free_node;
-        first_free_node = nodes[id].next;
-        return id;
-      }
-    }
-
-    void deleteNode(int id) {
-      nodes[id].next = first_free_node;
-      first_free_node = id;
-    }
-
-    Comp comp;
-
-    int findClass(int id) const {
-      int kd = id;
-      while (kd >= 0) {
-        kd = nodes[kd].parent;
-      }
-      return ~kd;
-    }
-
-    int leftNode(int id) const {
-      int kd = ~(classes[id].parent);
-      for (int i = 0; i < classes[id].depth; ++i) {
-        kd = nodes[kd].left;
-      }
-      return kd;
-    }
-
-    int nextNode(int id) const {
-      int depth = 0;
-      while (id >= 0 && nodes[id].next == -1) {
-        id = nodes[id].parent;
-        ++depth;
-      }
-      if (id < 0) {
-        return -1;
-      }
-      id = nodes[id].next;
-      while (depth--) {
-        id = nodes[id].left;      
-      }
-      return id;
-    }
-
-
-    void setPrio(int id) {
-      int jd = nodes[id].left;
-      nodes[id].prio = nodes[jd].prio;
-      nodes[id].item = nodes[jd].item;
-      jd = nodes[jd].next;
-      while (jd != -1) {
-        if (comp(nodes[jd].prio, nodes[id].prio)) {
-          nodes[id].prio = nodes[jd].prio;
-          nodes[id].item = nodes[jd].item;
-        }
-        jd = nodes[jd].next;
-      }
-    }
-
-    void push(int id, int jd) {
-      nodes[id].size = 1;
-      nodes[id].left = nodes[id].right = jd;
-      nodes[jd].next = nodes[jd].prev = -1;
-      nodes[jd].parent = id;
-    }
-
-    void pushAfter(int id, int jd) {
-      int kd = nodes[id].parent;
-      if (nodes[id].next != -1) {
-        nodes[nodes[id].next].prev = jd;
-        if (kd >= 0) {
-          nodes[kd].size += 1;
-        }
-      } else {
-        if (kd >= 0) {
-          nodes[kd].right = jd;
-          nodes[kd].size += 1;
-        }
-      }
-      nodes[jd].next = nodes[id].next;
-      nodes[jd].prev = id;
-      nodes[id].next = jd;
-      nodes[jd].parent = kd;
-    }
-
-    void pushRight(int id, int jd) {
-      nodes[id].size += 1;
-      nodes[jd].prev = nodes[id].right;
-      nodes[jd].next = -1;
-      nodes[nodes[id].right].next = jd;
-      nodes[id].right = jd;
-      nodes[jd].parent = id;
-    }
-
-    void popRight(int id) {
-      nodes[id].size -= 1;
-      int jd = nodes[id].right;
-      nodes[nodes[jd].prev].next = -1;
-      nodes[id].right = nodes[jd].prev;
-    }
-
-    void splice(int id, int jd) {
-      nodes[id].size += nodes[jd].size;
-      nodes[nodes[id].right].next = nodes[jd].left;
-      nodes[nodes[jd].left].prev = nodes[id].right;
-      int kd = nodes[jd].left;
-      while (kd != -1) {
-        nodes[kd].parent = id;
-        kd = nodes[kd].next;
-      }
-      nodes[id].right = nodes[jd].right;
-    }
-
-    void split(int id, int jd) {
-      int kd = nodes[id].parent;
-      nodes[kd].right = nodes[id].prev;
-      nodes[nodes[id].prev].next = -1;
-      
-      nodes[jd].left = id;
-      nodes[id].prev = -1;
-      int num = 0;
-      while (id != -1) {
-        nodes[id].parent = jd;
-        nodes[jd].right = id;
-        id = nodes[id].next;
-        ++num;
-      }      
-      nodes[kd].size -= num;
-      nodes[jd].size = num;
-    }
-
-    void pushLeft(int id, int jd) {
-      nodes[id].size += 1;
-      nodes[jd].next = nodes[id].left;
-      nodes[jd].prev = -1;
-      nodes[nodes[id].left].prev = jd;
-      nodes[id].left = jd;
-      nodes[jd].parent = id;
-    }
-
-    void popLeft(int id) {
-      nodes[id].size -= 1;
-      int jd = nodes[id].left;
-      nodes[nodes[jd].next].prev = -1;
-      nodes[id].left = nodes[jd].next;
-    }
-
-    void repairLeft(int id) {
-      int jd = ~(classes[id].parent);
-      while (nodes[jd].left != -1) {
-	int kd = nodes[jd].left;
-	if (nodes[jd].size == 1) {
-	  if (nodes[jd].parent < 0) {
-	    classes[id].parent = ~kd;
-	    classes[id].depth -= 1;
-	    nodes[kd].parent = ~id;
-	    deleteNode(jd);
-	    jd = kd;
-	  } else {
-	    int pd = nodes[jd].parent;
-	    if (nodes[nodes[jd].next].size < cmax) {
-	      pushLeft(nodes[jd].next, nodes[jd].left);
-	      if (less(nodes[jd].left, nodes[jd].next)) {
-		nodes[nodes[jd].next].prio = nodes[nodes[jd].left].prio;
-		nodes[nodes[jd].next].item = nodes[nodes[jd].left].item;
-	      } 
-	      popLeft(pd);
-	      deleteNode(jd);
-	      jd = pd;
-	    } else {
-	      int ld = nodes[nodes[jd].next].left;
-	      popLeft(nodes[jd].next);
-	      pushRight(jd, ld);
-	      if (less(ld, nodes[jd].left)) {
-		nodes[jd].item = nodes[ld].item;
-		nodes[jd].prio = nodes[jd].prio;
-	      }
-	      if (nodes[nodes[jd].next].item == nodes[ld].item) {
-		setPrio(nodes[jd].next);
-	      }
-	      jd = nodes[jd].left;
-	    }
-	  }
-	} else {
-	  jd = nodes[jd].left;
-	}
-      }
-    }    
-
-    void repairRight(int id) {
-      int jd = ~(classes[id].parent);
-      while (nodes[jd].right != -1) {
-	int kd = nodes[jd].right;
-	if (nodes[jd].size == 1) {
-	  if (nodes[jd].parent < 0) {
-	    classes[id].parent = ~kd;
-	    classes[id].depth -= 1;
-	    nodes[kd].parent = ~id;
-	    deleteNode(jd);
-	    jd = kd;
-	  } else {
-	    int pd = nodes[jd].parent;
-	    if (nodes[nodes[jd].prev].size < cmax) {
-	      pushRight(nodes[jd].prev, nodes[jd].right);
-	      if (less(nodes[jd].right, nodes[jd].prev)) {
-		nodes[nodes[jd].prev].prio = nodes[nodes[jd].right].prio;
-		nodes[nodes[jd].prev].item = nodes[nodes[jd].right].item;
-	      } 
-	      popRight(pd);
-	      deleteNode(jd);
-	      jd = pd;
-	    } else {
-	      int ld = nodes[nodes[jd].prev].right;
-	      popRight(nodes[jd].prev);
-	      pushLeft(jd, ld);
-	      if (less(ld, nodes[jd].right)) {
-		nodes[jd].item = nodes[ld].item;
-		nodes[jd].prio = nodes[jd].prio;
-	      }
-	      if (nodes[nodes[jd].prev].item == nodes[ld].item) {
-		setPrio(nodes[jd].prev);
-	      }
-	      jd = nodes[jd].right;
-	    }
-	  }
-	} else {
-	  jd = nodes[jd].right;
-	}
-      }
-    }
-
-
-    bool less(int id, int jd) const {
-      return comp(nodes[id].prio, nodes[jd].prio);
-    }
-
-    bool equal(int id, int jd) const {
-      return !less(id, jd) && !less(jd, id);
-    }
-
-
-  public:
-
-    /// \brief Returns true when the given class is alive.
-    ///
-    /// Returns true when the given class is alive, ie. the class is
-    /// not nested into other class.
-    bool alive(int cls) const {
-      return classes[cls].parent < 0;
-    }
-
-    /// \brief Returns true when the given class is trivial.
-    ///
-    /// Returns true when the given class is trivial, ie. the class
-    /// contains just one item directly.
-    bool trivial(int cls) const {
-      return classes[cls].left == -1;
-    }
-
-    /// \brief Constructs the union-find.
-    ///
-    /// Constructs the union-find.  
-    /// \brief _index The index map of the union-find. The data
-    /// structure uses internally for store references.
-    HeapUnionFind(ItemIntMap& _index) 
-      : index(_index), first_class(-1), 
-	first_free_class(-1), first_free_node(-1) {}
-
-    /// \brief Insert a new node into a new component.
-    ///
-    /// Insert a new node into a new component.
-    /// \param item The item of the new node.
-    /// \param prio The priority of the new node.
-    /// \return The class id of the one-item-heap.
-    int insert(const Item& item, const Value& prio) {
-      int id = newNode();
-      nodes[id].item = item;
-      nodes[id].prio = prio;
-      nodes[id].size = 0;
-
-      nodes[id].prev = -1;
-      nodes[id].next = -1;
-
-      nodes[id].left = -1;
-      nodes[id].right = -1;
-
-      nodes[id].item = item;
-      index[item] = id;
-      
-      int class_id = newClass();
-      classes[class_id].parent = ~id;
-      classes[class_id].depth = 0;
-
-      classes[class_id].left = -1;
-      classes[class_id].right = -1;
-      
-      if (first_class != -1) {
-        classes[first_class].prev = class_id;
-      }
-      classes[class_id].next = first_class;
-      classes[class_id].prev = -1;
-      first_class = class_id;
-
-      nodes[id].parent = ~class_id;
-      
-      return class_id;
-    }
-
-    /// \brief The class of the item.
-    ///
-    /// \return The alive class id of the item, which is not nested into
-    /// other classes.
-    ///
-    /// The time complexity is O(log(n)).
-    int find(const Item& item) const {
-      return findClass(index[item]);
-    }
-    
-    /// \brief Joins the classes.
-    ///
-    /// The current function joins the given classes. The parameter is
-    /// an STL range which should be contains valid class ids. The
-    /// time complexity is O(log(n)*k) where n is the overall number
-    /// of the joined nodes and k is the number of classes.
-    /// \return The class of the joined classes.
-    /// \pre The range should contain at least two class ids.
-    template <typename Iterator>
-    int join(Iterator begin, Iterator end) {
-      std::vector<int> cs;
-      for (Iterator it = begin; it != end; ++it) {
-        cs.push_back(*it);
-      }
-
-      int class_id = newClass();
-      { // creation union-find
-
-        if (first_class != -1) {
-          classes[first_class].prev = class_id;
-        }
-        classes[class_id].next = first_class;
-        classes[class_id].prev = -1;
-        first_class = class_id;
-
-        classes[class_id].depth = classes[cs[0]].depth;
-        classes[class_id].parent = classes[cs[0]].parent;
-        nodes[~(classes[class_id].parent)].parent = ~class_id;
-
-        int l = cs[0];
-
-        classes[class_id].left = l;
-        classes[class_id].right = l;
-
-        if (classes[l].next != -1) {
-          classes[classes[l].next].prev = classes[l].prev;
-        }
-        classes[classes[l].prev].next = classes[l].next;
-        
-        classes[l].prev = -1;
-        classes[l].next = -1;
-
-        classes[l].depth = leftNode(l);
-        classes[l].parent = class_id;
-        
-      }
-
-      { // merging of heap
-        int l = class_id;
-        for (int ci = 1; ci < int(cs.size()); ++ci) {
-          int r = cs[ci];
-          int rln = leftNode(r);
-          if (classes[l].depth > classes[r].depth) {
-            int id = ~(classes[l].parent);
-            for (int i = classes[r].depth + 1; i < classes[l].depth; ++i) {
-              id = nodes[id].right;
-            }
-            while (id >= 0 && nodes[id].size == cmax) {
-              int new_id = newNode();
-              int right_id = nodes[id].right;
-
-              popRight(id);
-              if (nodes[id].item == nodes[right_id].item) {
-                setPrio(id);
-              }
-              push(new_id, right_id);
-              pushRight(new_id, ~(classes[r].parent));
-              setPrio(new_id);
-
-              id = nodes[id].parent;
-              classes[r].parent = ~new_id;
-            }
-            if (id < 0) {
-              int new_parent = newNode();
-              nodes[new_parent].next = -1;
-              nodes[new_parent].prev = -1;
-              nodes[new_parent].parent = ~l;
-
-              push(new_parent, ~(classes[l].parent));
-              pushRight(new_parent, ~(classes[r].parent));
-              setPrio(new_parent);
-
-              classes[l].parent = ~new_parent;
-              classes[l].depth += 1;
-            } else {
-              pushRight(id, ~(classes[r].parent));
-              while (id >= 0 && less(~(classes[r].parent), id)) {
-                nodes[id].prio = nodes[~(classes[r].parent)].prio;
-                nodes[id].item = nodes[~(classes[r].parent)].item;
-                id = nodes[id].parent;
-              }
-            }
-          } else if (classes[r].depth > classes[l].depth) {
-            int id = ~(classes[r].parent);
-            for (int i = classes[l].depth + 1; i < classes[r].depth; ++i) {
-              id = nodes[id].left;
-            }
-            while (id >= 0 && nodes[id].size == cmax) {
-              int new_id = newNode();
-              int left_id = nodes[id].left;
-
-              popLeft(id);
-              if (nodes[id].prio == nodes[left_id].prio) {
-                setPrio(id);
-              }
-              push(new_id, left_id);
-              pushLeft(new_id, ~(classes[l].parent));
-              setPrio(new_id);
-
-              id = nodes[id].parent;
-              classes[l].parent = ~new_id;
-
-            }
-            if (id < 0) {
-              int new_parent = newNode();
-              nodes[new_parent].next = -1;
-              nodes[new_parent].prev = -1;
-              nodes[new_parent].parent = ~l;
-
-              push(new_parent, ~(classes[r].parent));
-              pushLeft(new_parent, ~(classes[l].parent));
-              setPrio(new_parent);
-              
-              classes[r].parent = ~new_parent;
-              classes[r].depth += 1;
-            } else {
-              pushLeft(id, ~(classes[l].parent));
-              while (id >= 0 && less(~(classes[l].parent), id)) {
-                nodes[id].prio = nodes[~(classes[l].parent)].prio;
-                nodes[id].item = nodes[~(classes[l].parent)].item;
-                id = nodes[id].parent;
-              }
-            }
-            nodes[~(classes[r].parent)].parent = ~l;
-            classes[l].parent = classes[r].parent;
-            classes[l].depth = classes[r].depth;
-          } else {
-            if (classes[l].depth != 0 && 
-                nodes[~(classes[l].parent)].size + 
-                nodes[~(classes[r].parent)].size <= cmax) {
-              splice(~(classes[l].parent), ~(classes[r].parent));
-              deleteNode(~(classes[r].parent));
-              if (less(~(classes[r].parent), ~(classes[l].parent))) {
-                nodes[~(classes[l].parent)].prio = 
-                  nodes[~(classes[r].parent)].prio;
-                nodes[~(classes[l].parent)].item = 
-                  nodes[~(classes[r].parent)].item;
-              }
-            } else {
-              int new_parent = newNode();
-              nodes[new_parent].next = nodes[new_parent].prev = -1;
-              push(new_parent, ~(classes[l].parent));
-              pushRight(new_parent, ~(classes[r].parent));
-              setPrio(new_parent);
-            
-              classes[l].parent = ~new_parent;
-              classes[l].depth += 1;
-              nodes[new_parent].parent = ~l;
-            }
-          }
-          if (classes[r].next != -1) {
-            classes[classes[r].next].prev = classes[r].prev;
-          }
-          classes[classes[r].prev].next = classes[r].next;
-
-          classes[r].prev = classes[l].right;
-          classes[classes[l].right].next = r;
-          classes[l].right = r;
-          classes[r].parent = l;
-
-          classes[r].next = -1;
-          classes[r].depth = rln;
-        }
-      }
-      return class_id;
-    }
-
-    /// \brief Split the class to subclasses.
-    ///
-    /// The current function splits the given class. The join, which
-    /// made the current class, stored a reference to the
-    /// subclasses. The \c splitClass() member restores the classes
-    /// and creates the heaps. The parameter is an STL output iterator
-    /// which will be filled with the subclass ids. The time
-    /// complexity is O(log(n)*k) where n is the overall number of
-    /// nodes in the splitted classes and k is the number of the
-    /// classes.
-    template <typename Iterator>
-    void split(int cls, Iterator out) {
-      std::vector<int> cs;
-      { // splitting union-find
-        int id = cls;
-        int l = classes[id].left;
-
-        classes[l].parent = classes[id].parent;
-        classes[l].depth = classes[id].depth;
-
-        nodes[~(classes[l].parent)].parent = ~l;
-
-        *out++ = l;
-
-        while (l != -1) {
-          cs.push_back(l);
-          l = classes[l].next;
-        }
-
-        classes[classes[id].right].next = first_class;
-        classes[first_class].prev = classes[id].right;
-        first_class = classes[id].left;
-        
-        if (classes[id].next != -1) {
-          classes[classes[id].next].prev = classes[id].prev;
-        }
-        classes[classes[id].prev].next = classes[id].next;
-        
-        deleteClass(id);
-      }
-
-      {
-        for (int i = 1; i < int(cs.size()); ++i) {
-          int l = classes[cs[i]].depth;
-          while (nodes[nodes[l].parent].left == l) {
-            l = nodes[l].parent;
-          }
-          int r = l;    
-          while (nodes[l].parent >= 0) {
-            l = nodes[l].parent;
-            int new_node = newNode();
-
-            nodes[new_node].prev = -1;
-            nodes[new_node].next = -1;
-
-            split(r, new_node);
-            pushAfter(l, new_node);
-            setPrio(l);
-            setPrio(new_node);
-            r = new_node;
-          }
-          classes[cs[i]].parent = ~r;
-          classes[cs[i]].depth = classes[~(nodes[l].parent)].depth;
-          nodes[r].parent = ~cs[i];
-
-          nodes[l].next = -1;
-          nodes[r].prev = -1;
-
-          repairRight(~(nodes[l].parent));
-          repairLeft(cs[i]);
-          
-          *out++ = cs[i];
-        }
-      }
-    }
-
-    /// \brief Gives back the priority of the current item.
-    ///
-    /// \return Gives back the priority of the current item.
-    const Value& operator[](const Item& item) const {
-      return nodes[index[item]].prio;
-    }
-
-    /// \brief Sets the priority of the current item.
-    ///
-    /// Sets the priority of the current item.
-    void set(const Item& item, const Value& prio) {
-      if (comp(prio, nodes[index[item]].prio)) {
-        decrease(item, prio);
-      } else if (!comp(prio, nodes[index[item]].prio)) {
-        increase(item, prio);
-      }
-    }
-      
-    /// \brief Increase the priority of the current item.
-    ///
-    /// Increase the priority of the current item.
-    void increase(const Item& item, const Value& prio) {
-      int id = index[item];
-      int kd = nodes[id].parent;
-      nodes[id].prio = prio;
-      while (kd >= 0 && nodes[kd].item == item) {
-        setPrio(kd);
-        kd = nodes[kd].parent;
-      }
-    }
-
-    /// \brief Increase the priority of the current item.
-    ///
-    /// Increase the priority of the current item.
-    void decrease(const Item& item, const Value& prio) {
-      int id = index[item];
-      int kd = nodes[id].parent;
-      nodes[id].prio = prio;
-      while (kd >= 0 && less(id, kd)) {
-        nodes[kd].prio = prio;
-        nodes[kd].item = item;
-        kd = nodes[kd].parent;
-      }
-    }
-    
-    /// \brief Gives back the minimum priority of the class.
-    ///
-    /// \return Gives back the minimum priority of the class.
-    const Value& classPrio(int cls) const {
-      return nodes[~(classes[cls].parent)].prio;
-    }
-
-    /// \brief Gives back the minimum priority item of the class.
-    ///
-    /// \return Gives back the minimum priority item of the class.
-    const Item& classTop(int cls) const {
-      return nodes[~(classes[cls].parent)].item;
-    }
-
-    /// \brief Gives back a representant item of the class.
-    /// 
-    /// The representant is indpendent from the priorities of the
-    /// items. 
-    /// \return Gives back a representant item of the class.
-    const Item& classRep(int id) const {
-      int parent = classes[id].parent;
-      return nodes[parent >= 0 ? classes[id].depth : leftNode(id)].item;
-    }
-
-    /// \brief Lemon style iterator for the items of a class.
-    ///
-    /// ClassIt is a lemon style iterator for the components. It iterates
-    /// on the items of a class. By example if you want to iterate on
-    /// each items of each classes then you may write the next code.
-    ///\code
-    /// for (ClassIt cit(huf); cit != INVALID; ++cit) {
-    ///   std::cout << "Class: ";
-    ///   for (ItemIt iit(huf, cit); iit != INVALID; ++iit) {
-    ///     std::cout << toString(iit) << ' ' << std::endl;
-    ///   }
-    ///   std::cout << std::endl;
-    /// }
-    ///\endcode
-    class ItemIt {
-    private:
-
-      const HeapUnionFind* _huf;
-      int _id, _lid;
-      
-    public:
-
-      /// \brief Default constructor 
-      ///
-      /// Default constructor 
-      ItemIt() {}
-
-      ItemIt(const HeapUnionFind& huf, int cls) : _huf(&huf) {
-        int id = cls;
-        int parent = _huf->classes[id].parent;
-        if (parent >= 0) {
-          _id = _huf->classes[id].depth;
-          if (_huf->classes[id].next != -1) {
-            _lid = _huf->classes[_huf->classes[id].next].depth;
-          } else {
-            _lid = -1;
-          }
-        } else {
-          _id = _huf->leftNode(id);
-          _lid = -1;
-        } 
-      }
-      
-      /// \brief Increment operator
-      ///
-      /// It steps to the next item in the class.
-      ItemIt& operator++() {
-        _id = _huf->nextNode(_id);
-        return *this;
-      }
-
-      /// \brief Conversion operator
-      ///
-      /// It converts the iterator to the current item.
-      operator const Item&() const {
-        return _huf->nodes[_id].item;
-      }
-      
-      /// \brief Equality operator
-      ///
-      /// Equality operator
-      bool operator==(const ItemIt& i) { 
-        return i._id == _id;
-      }
-
-      /// \brief Inequality operator
-      ///
-      /// Inequality operator
-      bool operator!=(const ItemIt& i) { 
-        return i._id != _id;
-      }
-
-      /// \brief Equality operator
-      ///
-      /// Equality operator
-      bool operator==(Invalid) { 
-        return _id == _lid;
-      }
-
-      /// \brief Inequality operator
-      ///
-      /// Inequality operator
-      bool operator!=(Invalid) { 
-        return _id != _lid;
-      }
-      
-    };
-
-    /// \brief Class iterator
-    ///
-    /// The iterator stores 
-    class ClassIt {
-    private:
-
-      const HeapUnionFind* _huf;
-      int _id;
-
-    public:
-
-      ClassIt(const HeapUnionFind& huf) 
-        : _huf(&huf), _id(huf.first_class) {}
-
-      ClassIt(const HeapUnionFind& huf, int cls) 
-        : _huf(&huf), _id(huf.classes[cls].left) {}
-
-      ClassIt(Invalid) : _huf(0), _id(-1) {}
-      
-      const ClassIt& operator++() {
-        _id = _huf->classes[_id].next;
-	return *this;
-      }
-
-      /// \brief Equality operator
-      ///
-      /// Equality operator
-      bool operator==(const ClassIt& i) { 
-        return i._id == _id;
-      }
-
-      /// \brief Inequality operator
-      ///
-      /// Inequality operator
-      bool operator!=(const ClassIt& i) { 
-        return i._id != _id;
-      }      
-      
-      operator int() const {
-	return _id;
-      }
-            
-    };
-
-  };
-
-  //! @}
-
-} //namespace lemon
-
-#endif //LEMON_UNION_FIND_H
