bfs correctness