Fixed memory errors in bfs.cc