This is somewhat ugly, but we do not want introduce a std::shared_ptr<> since G and explored could well be stack allocated.