Graph Theory37 sections · 1633 units
Open in Course

School Dance - Walkthrough

(Example with 3 boys, 2 girls)

Example: 33 boys, 33 girls. Boy 11 likes girls 11 and 22. Boy 22 likes girl 22. Boy 33 likes girl 33. Build the flow graph with source, boys, girls, and sink. All edges have capacity 11. Max flow is 33, meaning all boys can be paired. Edmonds-Karp finds augmenting paths:

1.1. sboy1girl1ts \to \text{boy}_1 \to \text{girl}_1 \to t (bottleneck 11).

2.2. sboy2girl2ts \to \text{boy}_2 \to \text{girl}_2 \to t (bottleneck 11).

3.3. sboy3girl3ts \to \text{boy}_3 \to \text{girl}_3 \to t (bottleneck 11).

Final pairs: (11,11), (22,22), (33,33). Output 33 pairs. The algorithm found a perfect matching where everyone dances.