Apply max flow/min cut algorithm (#711)