how to solve bfs problems