Update bfs.cpp

handle self-loop