refactoring: move min-cost max-flow code into separate class