Skip to content
  • Dashboard
  • Review
  • Go: plan & chat
  • Roadmap
  • Patterns & lessons49
  • Sheets
  • Problems1.5k
  • Ascend
  • Toolkit
  • Core CS + SQL
  • System Design
  • Machine Coding
  • Interview hub
  • Mock interview
  • Companies & OA
  • Leaderboard
  • Battles
  • College Cup
  • People

Keep your progress

Sync across devices with a free account.

Sign upSign in
Patterns & lessons
Sign inSign up
Patterns/Graphs/Maximum Flow / Minimum Cut

Technique

Bipartite Matching

Find the largest set of disjoint left-right pairs via augmenting paths (Kuhn) or flow; Hungarian for weighted assignment.

Learn firstBipartite Check / 2-ColouringMaximum Flow / Minimum CutUnlocksMinimum-Cost Flow (and the assignment problem)
0%
mastery
0/4 solved
Practise nextTask Assignment
IdeaPracticePitfalls

Recognise it

The signal

pair items of two groups by compatibility only (who can go with whom), maximising pairs

  1. 1Brute force

    Try all matchings.

  2. 2The observation

    Exponential search: augmenting paths increase matching by one each time.

  3. 3Why it works

    A matching is maximum iff no augmenting path exists.

Reach for it when

  • +minimum vertex cover in a bipartite graph (Konig)

Not when

  • ×general (non-bipartite) graphs need blossom
  • ×small n with bitmask DP may be simpler

Practice

Next

Task Assignment

0/4 solved
  • Coin GridCSESMedium
  • Task AssignmentCSESHard
  • Grid Puzzle IICSESHard
  • School DanceCSESHard

Pitfalls

Misconceptions

  • !greedy matching (fails)
  • !With costs on the pairs (minimise total cost) it's weighted assignment: Hungarian or min-cost flow, not maximum matching.

Looks like it, isn't

  • Task Assignment needs Minimum-Cost Flow (and the assignment problem)
    Why
    Every employee-task pair has a cost and the total is minimised: weighted assignment (Hungarian / MCMF), not max matching. source ↗
Go deeper2 combinations · resources

Combinations

  • Maximum Flow / Minimum Cut+Bipartite Matching

    pair two groups under compatibility constraints

    Maximum Flow / Minimum Cut:
    the solver (unit capacities)
    Bipartite Matching:
    the model (left-right compatibility)

    School Dance

  • Minimum-Cost Flow (and the assignment problem)+Bipartite Matching

    assign n employees to n tasks with a cost matrix, minimising the total

    Minimum-Cost Flow (and the assignment problem):
    minimises total cost over perfect matchings (Hungarian for dense n x n)
    Bipartite Matching:
    the left/right assignment structure

    Task AssignmentGrid Puzzle II

Resources

  • Graph Theory playlistWilliam Fiset · video
  • Graph TraversalUSACO Guide · course
  • Disjoint Set Unioncp-algorithms · article
  • Dijkstracp-algorithms · article
  • Topological sortingcp-algorithms · article
  • Shortest paths visualizerVisuAlgo · tool
  • Graph cheatsheetTech Interview Handbook · article
TodayReviewPatternsProblems