Code RoomMaximum flow minimum cost
HardPrep Room Coding #1263

Maximum flow minimum cost

CodingAlgorithms & data structuresSenior–Staff~45 min

A directed network on n nodes (0..n-1) has edges [u, v, cap, cost] meaning a pipe from u to v with the given capacity and a per-unit cost. Send the MAXIMUM possible flow from s to t, and among all maximum-flow solutions pick one of minimum total cost. Return [max_flow_value, min_total_cost]. All costs are non-negative. Constraints: 1 <= n <= 200; 0 <= cap, cost <= 1000.

Implement
min_cost_max_flow(n: int, edges: list[list[int]], s: int, t: int) → list[int]
Examples
in[4,[[0,1,3,1],[0,2,2,2],[1,3,2,1],[2,3,3,1],[1,2,1,1]],0,3]out[5,13]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 45 min
InputExpectedGot
[4,[[0,1,3,1],[0,2,2,2],[1,3,2,1],[2,3,3,1],[1,2,1,1]],0,3][5,13]not run yetsample