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/Graph BFS / DFS

Pattern

Maximum Flow / Minimum Cut

Push flow along augmenting paths in a residual graph; max flow equals min cut, which models assignment, disjoint paths, and separation problems.

Learn firstGraph BFS / DFS
0%
mastery
0/8 solved
Practise nextParcel Delivery
IdeaPracticePitfalls

Recognise it

The signal

capacities on edges, maximise throughput

  1. 1Brute force

    Enumerate edge subsets for cuts.

  2. 2The observation

    Exponential cut choices: augmenting paths with reverse edges let flow be rerouted.

  3. 3Why it works

    Flow is optimal iff no augmenting path exists in the residual graph.

Reach for it when

  • +edge-disjoint / vertex-disjoint paths
  • +cheapest set of edges to cut s from t

Not when

  • ×huge graphs typical of interviews (rarely asked in interviews; mostly CP)
  • ×costs on edges (min-cost flow)

Practice

Next

Parcel Delivery

0/8 solved
  • Parcel DeliveryCSESHard
  • Build StringCodeforces2000
  • School DanceCSESHard
  • Download SpeedCSESHard
  • Police ChaseCSESHard
  • Distinct RoutesCSESHard
  • Soldier and TravelingCodeforces2100
  • Petya and GraphCodeforces2400

Pitfalls

Misconceptions

  • !forgetting reverse residual edges
Go deepervariants and techniques · 2 combinations · resources

Variants and techniques

  • Bipartite MatchingFind the largest set of disjoint left-right pairs via augmenting paths (Kuhn) or flow; Hungarian for weighted assignment.
  • Minimum-Cost Flow (and the assignment problem)CP 2000Augment along cheapest paths: Bellman-Ford/SPFA once, then Dijkstra with Johnson potentials. This gives the minimum total cost for each flow value. Weighted bipartite assignment is the special case that the Hungarian algorithm solves in O(n^3).

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