diff --git a/lemon/list_graph.h b/lemon/list_graph.h --- a/lemon/list_graph.h +++ b/lemon/list_graph.h @@ -842,7 +842,9 @@ explicit Arc(int pid) { id = pid;} public: - operator Edge() const { return edgeFromId(id / 2); } + operator Edge() const { + return id != -1 ? edgeFromId(id / 2) : INVALID; + } Arc() {} Arc (Invalid) { id = -1; } diff --git a/lemon/smart_graph.h b/lemon/smart_graph.h --- a/lemon/smart_graph.h +++ b/lemon/smart_graph.h @@ -465,7 +465,9 @@ explicit Arc(int id) { _id = id;} public: - operator Edge() const { return edgeFromId(_id / 2); } + operator Edge() const { + return _id != -1 ? edgeFromId(_id / 2) : INVALID; + } Arc() {} Arc (Invalid) { _id = -1; }