Implemented some bfs algorithm