semi-bfs solve