Implement the connected block problem with new algorithm