Implemented the min cut algorithm