implement MinCostMaxFlow algorithm