03
Applications: Matching, Disjoint Paths, Scheduling
Chapter 3 • Advanced
150 min
Network Flow Applications
Bipartite Matching
Problem
Find maximum matching in bipartite graph.
Reduction to Max-Flow
- Add source connected to all left vertices
- Add sink connected to all right vertices
- Set all edge capacities to 1
- Max flow = max matching
python.js
def bipartite_matching(graph, left_size):
"""Maximum bipartite matching using max-flow"""
n = len(graph)
# Create flow network
flow_graph = [[0] * (n + 2) for _ in range(n + 2)]
source = n
sink = n + 1
# Connect source to left vertices
for i in range(left_size):
flow_graph[source][i] = 1
# Connect right vertices to sink
for i in range(left_size, n):
flow_graph[i][sink] = 1
# Original edges
for u in range(left_size):
for v in graph[u]:
flow_graph[u][v] = 1
return ford_fulkerson(flow_graph, source, sink)
Disjoint Paths
Find maximum number of edge-disjoint paths from s to t.
Solution: Set all capacities to 1, find max-flow.
Image Segmentation
Separate foreground from background.
Practice Problems
- Maximum bipartite matching
- Edge-disjoint paths
- Vertex-disjoint paths
- Image segmentation
- Project selection