Working algorithm. Need min cut