refactored Min Cut algorithm