Maximum Flow (Ford-Fulkerson) - Problem
Implement the Ford-Fulkerson algorithm to find the maximum flow in a flow network using BFS (Edmonds-Karp implementation).
Given a flow network represented as an adjacency matrix where capacity[u][v] represents the capacity of the edge from vertex u to vertex v, find the maximum flow from source s to sink t.
The Ford-Fulkerson method uses BFS to find augmenting paths and increases the flow along these paths until no more augmenting paths exist.
Key concepts:
- Flow Network: A directed graph where each edge has a capacity
- Augmenting Path: A path from source to sink with available capacity
- Residual Graph: Graph showing remaining capacities after current flow
- Max Flow Min Cut Theorem: Maximum flow equals minimum cut capacity
Input & Output
Example 1 — Basic Flow Network
$
Input:
capacity = [[0,16,13,0,0,0],[0,0,0,12,0,0],[0,4,0,0,14,0],[0,0,9,0,0,20],[0,0,0,7,0,4],[0,0,0,0,0,0]], source = 0, sink = 5
›
Output:
23
💡 Note:
Maximum flow from vertex 0 to vertex 5 is 23. Path 0→1→3→5 gives flow 12, path 0→2→4→5 gives flow 4, path 0→2→4→3→5 gives flow 7.
Example 2 — Simple Network
$
Input:
capacity = [[0,10,10,0],[0,0,0,10],[0,0,0,10],[0,0,0,0]], source = 0, sink = 3
›
Output:
20
💡 Note:
Two paths: 0→1→3 with flow 10 and 0→2→3 with flow 10. Total maximum flow is 20.
Example 3 — Bottleneck Network
$
Input:
capacity = [[0,100,0,100],[0,0,1,0],[0,0,0,100],[0,0,0,0]], source = 0, sink = 3
›
Output:
101
💡 Note:
Direct path 0→3 gives flow 100, path 0→1→2→3 gives flow 1. Bottleneck at edge 1→2 limits this path.
Constraints
- 1 ≤ vertices ≤ 100
- 0 ≤ capacity[i][j] ≤ 1000
- 0 ≤ source, sink < vertices
- source ≠ sink
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code