C++ implementation of a bidirectional graph