finish bfs