{"id":"maximum-bipartite-matching","title":"Maximum Bipartite Matching","difficulty":"medium","patterns":["bipartite-matching"],"primaryConcept":"graph-bipartite-matching","concepts":["graph-bipartite-matching"],"problemForm":"core","companies":["Google","Amazon","Meta","Microsoft"],"category":"trees-graphs","executionStyle":"solution-method","compareMode":"exact","syntheticTestConfig":{"inputShape":"graph-edges","primaryParam":"edges","sizeMetric":"nodes-plus-edges","secondaryParams":{"leftCount":{"strategy":"scale-with-primary"},"rightCount":{"strategy":"scale-with-primary"}}},"description":"You are given `leftCount` nodes on the left side, `rightCount` nodes on the right side, and bipartite edges where each edge is `[left, right]`.\n\nReturn the size of the maximum matching: the largest number of edges you can choose so that no chosen edges share a left node or a right node.","examples":[{"input":"leftCount = 3, rightCount = 3, edges = [[0,0],[0,1],[1,1],[2,2]]","output":"3","explanation":"Use matches 0-0, 1-1, and 2-2."},{"input":"leftCount = 2, rightCount = 2, edges = [[0,0],[1,0]]","output":"1","explanation":"Both left nodes want the same right node, so only one match is possible."}],"constraints":[{"id":"0-leftcount-rightcount-200","text":"0 <= leftCount, rightCount <= 200","check":[{"kind":"valueRange","target":"leftCount","selector":"value","min":0,"max":200},{"kind":"valueRange","target":"rightCount","selector":"value","min":0,"max":200}]},{"id":"0-len-edges-5000","text":"0 <= len(edges) <= 5000","check":{"kind":"sizeRange","target":"edges","measure":"arrayLength","min":0,"max":5000}},{"id":"each-edge-is-left-right","text":"Each edge is [left, right]","check":{"kind":"shape","target":"edges","shape":"tupleArray","tupleLength":2}},{"id":"0-left-leftcount","text":"0 <= left < leftCount","check":{"kind":"valueRange","target":"edges","selector":"tupleItemsAtIndex","index":0,"min":0,"max":{"valueOfInput":"leftCount","offset":-1}}},{"id":"0-right-rightcount","text":"0 <= right < rightCount","check":{"kind":"valueRange","target":"edges","selector":"tupleItemsAtIndex","index":1,"min":0,"max":{"valueOfInput":"rightCount","offset":-1}}}],"starterCode":"class Solution:\n    def maximumBipartiteMatching(self, leftCount: int, rightCount: int, edges: list[list[int]]) -> int:\n        # Your code here\n        pass","functionName":"maximumBipartiteMatching","testCases":[{"id":"1","input":{"leftCount":3,"rightCount":3,"edges":[[0,0],[0,1],[1,1],[2,2]]},"expected":3,"description":"All left nodes can be matched."},{"id":"2","input":{"leftCount":2,"rightCount":2,"edges":[[0,0],[1,0]]},"expected":1,"description":"Only one right node is available."},{"id":"3","input":{"leftCount":2,"rightCount":2,"edges":[[0,0],[0,1],[1,0]]},"expected":2,"description":"The second search must reroute the first match."},{"id":"4","input":{"leftCount":3,"rightCount":2,"edges":[]},"expected":0,"description":"No edges means no matches."},{"id":"5","input":{"leftCount":4,"rightCount":3,"edges":[[0,0],[0,1],[1,1],[2,1],[2,2],[3,2]]},"expected":3,"description":"More left nodes than right nodes caps the answer at rightCount."},{"id":"h1","input":{"leftCount":0,"rightCount":3,"edges":[]},"expected":0,"description":"No left-side nodes."},{"id":"h2","input":{"leftCount":3,"rightCount":0,"edges":[]},"expected":0,"description":"No right-side nodes."},{"id":"h3","input":{"leftCount":5,"rightCount":5,"edges":[[0,1],[1,0],[1,2],[2,2],[3,3],[4,3],[4,4]]},"expected":5,"description":"Several augmenting paths unlock a perfect matching."},{"id":"h4","input":{"leftCount":3,"rightCount":2,"edges":[[0,0],[0,1],[1,0],[1,1],[2,0],[2,1]]},"expected":2,"description":"A complete 3-by-2 bipartite graph is capped by the right side."},{"id":"h5","input":{"leftCount":2,"rightCount":2,"edges":[[0,0],[0,0],[0,1],[1,1]]},"expected":2,"description":"Duplicate edges should not change the maximum matching size."},{"id":"disconnected-components-perfect","input":{"leftCount":4,"rightCount":4,"edges":[[0,0],[1,0],[1,1],[2,2],[3,2],[3,3]]},"expected":4,"description":"Disconnected components can still combine into a perfect matching."},{"id":"isolated-left-node","input":{"leftCount":4,"rightCount":3,"edges":[[0,0],[1,1],[2,1],[2,2]]},"expected":3,"description":"An isolated left node does not prevent the other nodes from filling the right side."}],"hints":[{"level":1,"content":"Store each left node's right-side neighbors in an adjacency list."},{"level":2,"content":"A DFS can claim an unmatched right node or reroute the left node that currently owns it."},{"level":3,"content":"Reset the right-side visited array for each new left node's augmenting search."}],"guidedFlow":{"version":2,"approachSelection":{"contract":"approach-selection-v1","question":"Which implementation should we use?","decisionPrompt":"Choose the approach whose state and complexity match the problem constraints.","approaches":[{"id":"greedy-first-fit","name":"Greedy first fit","summary":"Assign each left node to the first free right node it can use.","decisionReason":"First fit commits each left node to the first free right node and never revisits. One early claim can take the only right node a later left node could use, and without rerouting the count stalls below the true maximum.","complexity":{"time":"O(E)","space":"O(R)"},"tradeoffs":["Runs in O(E) time and uses O(R) space."],"isOptimal":false},{"id":"augmenting-dfs","name":"Augmenting DFS","summary":"Try to reroute existing matches so each left node can increase the matching if possible.","decisionReason":"When a left node finds its choices taken, the search asks a current holder to move to its other option, and that reroute is the only operation that grows a stuck matching. Each left node triggers at most one pass over the edges, well within the constraints.","complexity":{"time":"O(L * E)","space":"O(L + R + E)"},"tradeoffs":["Runs in O(L * E) time and uses O(L + R + E) space."],"isOptimal":true}]},"codingCheckpoints":[{"id":"build-adj","title":"Build adjacency","description":"Convert the edge list into neighbors for each left node.","commonMistakes":["Adding right nodes to the wrong left bucket","Treating edges as undirected"],"hint":"Each edge `[left, right]` should append `right` to `adj[left]`.","semanticSpec":{"intent":"Build the bipartite adjacency state.","doneWhen":"Every edge contributes a right-side neighbor under its left node.","shouldFailWhen":"This step should fail if the matching search has no adjacency state.","roles":["left node","right node","adjacency"],"mustProve":["Bipartite adjacency state is built."],"mustNotAccept":["A flat list with no left-to-right grouping."],"equivalentVariants":["Use arrays, lists, or maps for left-side buckets."]},"validation":{"type":"semantic","validator":"familyFact","params":[{"family":"bipartite-matching","fact":"builds_bipartite_adjacency_state","scope":"build-adj","readMode":"bipartite-matching-value-query-v1"}]}},{"id":"dfs-match","title":"Define augmenting DFS","description":"Create a helper that claims free right nodes or reroutes their current owners.","commonMistakes":["Only accepting currently free right nodes","Not marking right nodes as seen"],"hint":"If `right` is already matched, recursively search from its current owner.","semanticSpec":{"intent":"Define the augmenting-path reroute helper.","doneWhen":"The helper recurses through current right-side owners and updates matches when rerouting succeeds.","shouldFailWhen":"This step should fail if the helper is greedy and never reroutes.","roles":["left node","right node","match state"],"mustProve":["An augmenting reroute helper is defined."],"mustNotAccept":["A first-free-only greedy assignment."],"equivalentVariants":["Use DFS as an inner function or helper method."]},"validation":{"type":"semantic","validator":"familyFact","params":[{"family":"bipartite-matching","fact":"defines_augmenting_reroute_helper","scope":"dfs-match","readMode":"bipartite-matching-value-query-v1"}]}},{"id":"reset-seen","title":"Search with fresh seen state","description":"Run one augmenting DFS per left node with a new right-side seen array.","commonMistakes":["Reusing seen state across different left nodes","Never attempting unmatched left nodes"],"hint":"The seen array prevents cycles inside one DFS, but it must reset for the next root.","semanticSpec":{"intent":"Execute augmenting searches with fresh visited state.","doneWhen":"Each root search allocates fresh right-side visited state and calls the helper.","shouldFailWhen":"This step should fail if visited state is shared across root searches.","roles":["root left node","seen state","augmenting helper"],"mustProve":["Augmenting search executes with fresh visited state."],"mustNotAccept":["A global seen set shared by all root searches."],"equivalentVariants":["Use boolean arrays, sets, or equivalent per-search state."]},"validation":{"type":"semantic","validator":"familyFact","params":[{"family":"bipartite-matching","fact":"executes_augmenting_search_with_fresh_visited_state","scope":"reset-seen","readMode":"bipartite-matching-value-query-v1"}]}},{"id":"matching-answer","title":"Return matching size","description":"Count successful augmenting searches and return that count.","commonMistakes":["Returning the match array instead of its size","Counting attempted searches instead of successful ones"],"hint":"Only increment when DFS actually finds an augmenting path.","semanticSpec":{"intent":"Return the size of the maximum matching after augmenting search.","doneWhen":"The function returns the count of successful augmenting paths.","shouldFailWhen":"This step should fail if the returned count is unrelated to matching success.","roles":["matching count","augmenting success"],"mustProve":["The matching size is returned after augmenting search."],"mustNotAccept":["Returning the number of edges or left nodes."],"equivalentVariants":["Count successes directly or count filled right-side match entries."]},"validation":{"type":"semantic","validator":"familyFact","params":[{"family":"bipartite-matching","fact":"returns_matching_size_after_augmenting_search","scope":"matching-answer","readMode":"bipartite-matching-value-query-v1"}]}}],"slides":[{"id":"read-the-problem","chapter":"The task","kind":"info","eyebrow":"Read the problem","title":"Pair as many left nodes with right nodes as you can","workspacePanel":"problem","body":["You get leftCount nodes on the left, rightCount nodes on the right, and edges that say which left node may pair with which right node. Choose as many edges as possible so no two chosen edges share a left node or a right node. Return that count.","Each chosen edge claims one node on each side, so the answer can never exceed the smaller side."]},{"id":"greedy-baseline","chapter":"The obvious way","kind":"code-trace","eyebrow":"The obvious way","title":"Hand each left node the first free right node","summary":"Walk the left nodes in order, and for each one grab the first right node in its list that nobody has taken yet.","workspacePanel":"trace","codeTrace":{"contract":"guided-code-trace-v1","languageLabel":"Python","editorLanguage":"python","code":"def maximumBipartiteMatching(leftCount: int, rightCount: int, edges: list[list[int]]) -> int:\n    adj = [[] for _ in range(leftCount)]\n    for left, right in edges:\n        adj[left].append(right)\n\n    taken = [False] * rightCount\n    matched = 0\n    for left in range(leftCount):\n        for right in adj[left]:\n            if not taken[right]:\n                taken[right] = True\n                matched += 1\n                break\n    return matched","steps":[{"id":"left0","title":"Left 0 takes the first free right node","codeLine":10,"summary":"Left 0's options are right 0 then right 1. Right 0 is free, so left 0 grabs it and stops looking.","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L0","highlighted":["R0"],"activeEdges":[["L0","R0"]]}}},{"id":"left1","title":"Left 1 finds its only option already taken","codeLine":10,"summary":"Left 1 can use only right 0, but left 0 holds it. The loop finds nothing free and leaves left 1 unmatched.","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L1","highlighted":["R0"],"activeEdges":[["L0","R0"]]}}},{"id":"result","title":"Greedy returns 1","codeLine":14,"summary":"Only left 0 is matched, so this returns 1. Right 1 sat free the whole time while left 1 went unpaired.","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"activeEdges":[["L0","R0"]]}}}],"localizations":{"javascript":{"languageLabel":"JavaScript","editorLanguage":"javascript","codeStyle":"natural","code":"const adj = Array.from({ length: leftCount }, () => []);\nfor (const [left, right] of edges) {\n    adj[left].push(right);\n}\nconst taken = Array(rightCount).fill(false);\nlet matched = 0;\nfor (let left = 0; left < leftCount; left++) {\n    for (const right of adj[left]) {\n        if (!taken[right]) {\n            taken[right] = true;\n            matched++;\n            break;\n        }\n    }\n}\nreturn matched;","lineMap":{"2":1,"3":2,"4":3,"6":5,"7":6,"8":7,"9":8,"10":9,"11":10,"12":11,"13":12,"14":16},"statementBundles":{"4":{"startLine":3,"endLine":4},"13":{"startLine":12,"endLine":15}}},"typescript":{"languageLabel":"TypeScript","editorLanguage":"typescript","codeStyle":"natural","code":"const adj: Array<Array<number>> = Array.from({ length: leftCount }, () => []);\nfor (const [left, right] of edges) {\n    adj[left].push(right);\n}\nconst taken = Array(rightCount).fill(false);\nlet matched = 0;\nfor (let left = 0; left < leftCount; left++) {\n    for (const right of adj[left]) {\n        if (!taken[right]) {\n            taken[right] = true;\n            matched++;\n            break;\n        }\n    }\n}\nreturn matched;","lineMap":{"2":1,"3":2,"4":3,"6":5,"7":6,"8":7,"9":8,"10":9,"11":10,"12":11,"13":12,"14":16},"statementBundles":{"4":{"startLine":3,"endLine":4},"13":{"startLine":12,"endLine":15}}},"java":{"languageLabel":"Java","editorLanguage":"java","codeStyle":"natural","code":"List<List<Integer>> adj = new ArrayList<>();\nfor (int i = 0; i < leftCount; i++) {\n    adj.add(new ArrayList<>());\n}\nfor (List<Integer> edge : edges) {\n    int left = edge.get(0);\n    int right = edge.get(1);\n    adj.get(left).add(right);\n}\nList<Boolean> taken = new ArrayList<>();\nfor (int index = 0; index < rightCount; index++) {\n    taken.add(false);\n}\nint matched = 0;\nfor (int left = 0; left < leftCount; left++) {\n    for (Integer right : adj.get(left)) {\n        if (!taken.get(right)) {\n            taken.set(right, true);\n            matched++;\n            break;\n        }\n    }\n}\nreturn matched;","lineMap":{"2":1,"3":5,"4":8,"6":10,"7":14,"8":15,"9":16,"10":17,"11":18,"12":19,"13":20,"14":24},"statementBundles":{"2":{"startLine":1,"endLine":4},"3":{"startLine":5,"endLine":7},"4":{"startLine":8,"endLine":9},"6":{"startLine":10,"endLine":13},"13":{"startLine":20,"endLine":23}}},"csharp":{"languageLabel":"C#","editorLanguage":"csharp","codeStyle":"natural","code":"List<List<int>> adj = Enumerable.Range(0, leftCount).Select(_ => new List<int>()).ToList();\nforeach (var item in edges) {\n    int left = item[0];\n    int right = item[1];\n    adj[left].Add(right);\n}\nList<bool> taken = Enumerable.Repeat<bool>(false, rightCount).ToList();\nint matched = 0;\nfor (int left = 0; left < leftCount; left++) {\n    foreach (int right in adj[left]) {\n        if (!taken[right]) {\n            taken[right] = true;\n            matched++;\n            break;\n        }\n    }\n}\nreturn matched;","lineMap":{"2":1,"3":2,"4":5,"6":7,"7":8,"8":9,"9":10,"10":11,"11":12,"12":13,"13":14,"14":18},"statementBundles":{"3":{"startLine":2,"endLine":4},"4":{"startLine":5,"endLine":6},"13":{"startLine":14,"endLine":17}}},"cpp":{"languageLabel":"C++","editorLanguage":"cpp","codeStyle":"natural","code":"vector<vector<int>> adj = vector<vector<int>>(left_count, vector<int>{});\nfor (vector<int> item : edges) {\n    int left = item[0];\n    int right = item[1];\n    adj[left].push_back(right);\n}\nvector<bool> taken = vector<bool>(right_count, false);\nint matched = 0;\nfor (int left = 0; left < left_count; left++) {\n    for (int right : adj[left]) {\n        if (!taken[right]) {\n            taken[right] = true;\n            matched++;\n            break;\n        }\n    }\n}\nreturn matched;","lineMap":{"2":1,"3":2,"4":5,"6":7,"7":8,"8":9,"9":10,"10":11,"11":12,"12":13,"13":14,"14":18},"statementBundles":{"3":{"startLine":2,"endLine":4},"4":{"startLine":5,"endLine":6},"13":{"startLine":14,"endLine":17}}}}}},{"id":"greedy-cost","chapter":"The obvious way","kind":"case-probe","eyebrow":"Why it hurts","title":"Why did greedy miss a pairing that exists?","summary":"Right 1 stayed free, yet left 1 ended up unmatched.","workspacePanel":"trace","options":[{"id":"early-grab","label":"Left 0 grabbed right 0 first, the one right node left 1 also needed","rationale":"Left 0 had a spare option in right 1, but it took right 0 anyway and never reconsidered. Left 1 had no spare, so the early grab cost a pairing that a swap would have saved.","isCorrect":true},{"id":"wrong-order","label":"The left nodes were processed in the wrong order","rationale":"Reordering only moves the conflict. Whichever node grabs a shared right node first can still strand a later node with no spare, unless an earlier choice can be revised.","isCorrect":false},{"id":"missing-edge","label":"An edge was missing from the input","rationale":"Every edge is present. The two pairings exist in the graph; greedy just locked in a choice it should have been willing to undo.","isCorrect":false}],"answer":"Left 0 took right 0, the single right node left 1 also needed, even though left 0 could have used right 1. Greedy never revisits a placed match, so a fixable conflict becomes a lost pairing."},{"id":"augment-insight","chapter":"The idea","kind":"case-probe","eyebrow":"Find the move","title":"Left 1 wants a right node that left 0 holds. What rescues the match?","summary":"Left 1 can use only right 0, currently owned by left 0, and left 0 still has right 1 open.","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"conflict","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L1","highlighted":["R0"],"activeEdges":[["L0","R0"]]}}}]},"options":[{"id":"reroute-owner","label":"Ask right 0's current owner, left 0, to move to another open right node","rationale":"Left 0 still has right 1 free. Moving left 0 to right 1 releases right 0 for left 1, so both end up matched. The search hands the conflict to the current owner and lets it step aside.","isCorrect":true},{"id":"give-up","label":"Leave left 1 unmatched, since its only right node is taken","rationale":"That is exactly greedy's mistake. The owner of right 0 can relocate, so a taken right node is not a dead end yet.","isCorrect":false},{"id":"drop-left0","label":"Unmatch left 0 entirely and give right 0 to left 1","rationale":"Dropping left 0 trades one match for another and never grows the total. The win comes from relocating left 0 to a free right node, not abandoning its match.","isCorrect":false}],"answer":"Ask right 0's owner, left 0, to relocate. Left 0 still has right 1 open, so it moves there and frees right 0 for left 1. Both sides end up matched."},{"id":"augmenting-invariant","chapter":"The idea","kind":"case-probe","eyebrow":"Name the rule","title":"When can a left node be added without unmatching anyone?","summary":"A relocation can cascade: the owner you ask to move may itself have to ask its own right node's owner to move.","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"rerouted","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R1"],["L1","R0"]],"activeEdges":[["L0","R1"],["L1","R0"]]}}}]},"options":[{"id":"chain-to-free","label":"When the chain of relocations ends at a right node nobody owns","rationale":"Each owner asked to move either finds a free right node or passes the request along its own edges. If the chain ever reaches an unowned right node, every node on it shifts by one and the matching grows by exactly one.","isCorrect":true},{"id":"any-edge","label":"Whenever the new left node has at least one edge","rationale":"Having an edge is not enough. If every right node it can reach is owned by a node that also has nowhere to move, the chain dead-ends and the matching cannot grow.","isCorrect":false},{"id":"free-right-now","label":"Only when one of its right nodes is free right now","rationale":"An immediately free right node is the easy case, but a fully occupied neighborhood can still open up if its owners can relocate down the chain. Requiring a free node up front misses those.","isCorrect":false}],"answer":"When the chain of relocations reaches a right node nobody owns. Every node along that chain shifts by one, freeing the spot the new left node needs and lifting the matching by one."},{"id":"approach-selection","kind":"choice","source":"approach-selection","chapter":"The idea","title":"Which search should each left node run?","eyebrow":"Pick the route","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"graph","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]]}}}]},"selection":{"contract":"approach-selection-v1","question":"Which implementation should we use?","decisionPrompt":"Choose the approach whose state and complexity match the problem constraints.","approaches":[{"id":"greedy-first-fit","name":"Greedy first fit","summary":"Assign each left node to the first free right node it can use.","decisionReason":"It pairs left 0 with right 0 and then strands left 1, because it never revisits a placed match. The conflict the relocation chain solves is exactly what this approach drops.","complexity":{"time":"O(E)","space":"O(R)"},"tradeoffs":["Runs in O(E) time and uses O(R) space."],"isOptimal":false},{"id":"augmenting-dfs","name":"Augmenting DFS","summary":"Run a DFS from each left node that follows the relocation chain, moving owners aside until it reaches a free right node.","decisionReason":"The DFS is the relocation chain made concrete: each left node either takes a free right node or asks an owner to move down its own edges. It recovers the pairings greedy loses.","complexity":{"time":"O(L * E)","space":"O(L + R + E)"},"tradeoffs":["Runs in O(L * E) time and uses O(L + R + E) space."],"isOptimal":true}]}},{"id":"dry-run-setup","chapter":"Trace","kind":"info","eyebrow":"Watch it move","title":"Run one search per left node","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"start","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L0"}}}]},"body":["Take the same graph: left 0 reaches right 0 and right 1, left 1 reaches only right 0. The first search is about to begin from left 0, highlighted as current. No right node is claimed yet. The search visits each left node once. It claims a free right node when it sees one, and when the right node is owned, it asks that owner to relocate down its own edges.","Watch the matched edges, drawn bold, change as the second search reroutes the first."]},{"id":"trace","kind":"dry-run","source":"trace-example","chapter":"Trace","title":"Trace the rerouting search","eyebrow":"Trace the state","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"match-l0","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L0","highlighted":["R0"],"activeEdges":[["L0","R0"]]}}},{"id":"l1-wants-r0","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L1","highlighted":["R0"],"activeEdges":[["L0","R0"]]}}},{"id":"reroute-l0","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L0","highlighted":["R1"],"activeEdges":[["L0","R1"]]}}},{"id":"both-matched","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R1"],["L1","R0"]],"activeEdges":[["L0","R1"],["L1","R0"]]}}}]},"beats":[{"id":"match-l0","title":"Left 0's search runs first. Which right node does it take?","summary":"Nothing is matched yet. Left 0 can reach right 0 or right 1.","prompt":"Left 0 runs its search.","options":[{"id":"takes-r0","label":"It claims right 0, the first free node it reaches","rationale":"Both of left 0's right nodes are free, so the search takes the first one it visits and records left 0 as right 0's owner.","isCorrect":true},{"id":"takes-both","label":"It claims both right 0 and right 1","rationale":"A left node can own only one right node at a time. The search stops at the first right node it successfully claims.","isCorrect":false},{"id":"skips","label":"It waits to see if left 1 needs right 0","rationale":"The search has no foresight. Left 0 claims a right node now, and a later search reroutes it if needed.","isCorrect":false}],"answer":"It claims right 0, the first free right node it reaches, and becomes its owner."},{"id":"l1-wants-r0","title":"Left 1 can reach only right 0, and left 0 owns it. What does the search do?","summary":"Left 1's single edge points at right 0, currently owned by left 0.","prompt":"Left 1 runs its search.","options":[{"id":"ask-owner","label":"It asks right 0's owner, left 0, to find another right node","rationale":"A taken right node is not a dead end. The search recurses into the current owner to see whether that owner can relocate, which would free right 0.","isCorrect":true},{"id":"fails","label":"It fails immediately, since right 0 is taken","rationale":"That is the greedy mistake. The owner may have a spare right node, so the search tries to relocate it before giving up.","isCorrect":false},{"id":"evict","label":"It evicts left 0 and leaves it unmatched","rationale":"Evicting trades one match for another and never grows the total. The search relocates the owner instead of abandoning its match.","isCorrect":false}],"answer":"It recurses into left 0, right 0's owner, to ask whether left 0 can move to a different right node."},{"id":"reroute-l0","title":"Left 0 is asked to move. Where does it go?","summary":"Left 0 has already checked one edge; one unvisited candidate remains.","prompt":"Choose the outcome of this relocation attempt.","options":[{"id":"to-r1","label":"Left 0 moves to right 1, freeing right 0 for left 1","rationale":"Right 1 is free, so left 0 relocates there. That releases right 0, the chain reaches an unowned right node, and the relocation succeeds back up to left 1.","isCorrect":true},{"id":"stuck","label":"Left 0 has nowhere to go, so the reroute fails","rationale":"Left 0 still has right 1 open, so it does have somewhere to go. The chain ends at a free right node.","isCorrect":false},{"id":"back-r0","label":"Left 0 stays on right 0 and left 1 takes right 1","rationale":"Left 1 has no edge to right 1, so it cannot take it. The relocation has to move left 0, not left 1.","isCorrect":false}],"answer":"Left 0 moves to the free right 1. That frees right 0, and left 1 claims it, so the chain lifts the matching to two."},{"id":"both-matched","title":"After both searches finish, what is the matching size?","prompt":"Read the bold matched edges off the graph.","options":[{"id":"two","label":"2: left 0 with right 1 and left 1 with right 0","rationale":"The reroute paired both left nodes, so two edges are matched. This beats greedy's one.","isCorrect":true},{"id":"one","label":"1, the same as greedy","rationale":"The relocation chain rescued left 1, so the matching is two, not one. That is the whole point of rerouting.","isCorrect":false},{"id":"three","label":"3, every node is used","rationale":"There are only two right nodes, so at most two edges can be matched. The answer is capped by the smaller side.","isCorrect":false}],"answer":"Two: left 0 with right 1 and left 1 with right 0. The relocation grew the matching past what greedy reached."}]},{"id":"seen-pitfall","chapter":"Trace","kind":"pitfall","eyebrow":"Spot the trap","title":"Can one visited marker serve every left node's search?","summary":"Marking each right node visited stops a single search from looping forever. A mistaken version allocates that marker once and reuses it across all the left nodes. Every test with one search per conflict still passes. Watch what happens when a later search needs a right node an earlier search already touched.","workspacePanel":"trace","pitfall":"The seen array is created once, outside the per-left loop, so right nodes touched by left 0's search stay marked when left 1 searches.","whyItMatters":"A right node marked during an earlier search looks visited to a later one, so the later search skips it and reports no augmenting path even when one exists. Allocate fresh seen state for each left node's search so every root starts with a clean view.","negativeTrace":{"contract":"negative-trace-v1","languageLabel":"Python","editorLanguage":"python","code":"def maximumBipartiteMatching(leftCount: int, rightCount: int, edges: list[list[int]]) -> int:\n    adj = [[] for _ in range(leftCount)]\n    for left, right in edges:\n        adj[left].append(right)\n\n    match_right = [-1] * rightCount\n    seen = [False] * rightCount\n\n    def dfs(left: int) -> bool:\n        for right in adj[left]:\n            if seen[right]:\n                continue\n            seen[right] = True\n            if match_right[right] == -1 or dfs(match_right[right]):\n                match_right[right] = left\n                return True\n        return False\n\n    matched = 0\n    for left in range(leftCount):\n        if dfs(left):\n            matched += 1\n    return matched","steps":[{"id":"l0-marks-r0","title":"Left 0's search marks right 0 and claims it","codeLine":13,"summary":"Left 0 visits right 0, marks it seen, and takes it. The shared seen array now holds that mark.","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L0","highlighted":["R0"],"activeEdges":[["L0","R0"]]}}},{"id":"l1-skips-r0","title":"Left 1 sees right 0 already marked and skips it","codeLine":11,"summary":"Right 0 is still marked from left 0's search. Left 1's only edge points at right 0, which now looks visited, so the search skips it.","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"current":"L1","highlighted":["R0"]}}},{"id":"wrong-answer","title":"It returns 1","codeLine":23,"summary":"Left 1's search never asks left 0 to relocate, because right 0 looked visited. The reroute that should have paired both nodes never happens, so this returns 1 instead of 2.","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]],"activeEdges":[["L0","R0"]]}}}],"localizations":{"javascript":{"languageLabel":"JavaScript","editorLanguage":"javascript","codeStyle":"natural","code":"const adj = Array.from({ length: leftCount }, () => []);\nfor (const [left, right] of edges) {\n    adj[left].push(right);\n}\nconst matchRight = Array(rightCount).fill(-1);\nconst seen = Array(rightCount).fill(false);\nfunction dfs(left) {\n    for (const right of adj[left]) {\n        if (seen[right]) {\n            continue;\n        }\n        seen[right] = true;\n        if (matchRight[right] === -1 || dfs(matchRight[right])) {\n            matchRight[right] = left;\n            return true;\n        }\n    }\n    return false;\n}\nlet matched = 0;\nfor (let left = 0; left < leftCount; left++) {\n    if (dfs(left)) {\n        matched++;\n    }\n}\nreturn matched;","lineMap":{"2":1,"3":2,"4":3,"6":5,"7":6,"10":8,"11":9,"12":10,"13":12,"14":13,"15":14,"16":15,"17":18,"19":20,"20":21,"21":22,"22":23,"23":26},"statementBundles":{"4":{"startLine":3,"endLine":4},"7":{"startLine":6,"endLine":7},"12":{"startLine":10,"endLine":11},"16":{"startLine":15,"endLine":17},"17":{"startLine":18,"endLine":19},"22":{"startLine":23,"endLine":25}}},"typescript":{"languageLabel":"TypeScript","editorLanguage":"typescript","codeStyle":"natural","code":"const adj: Array<Array<number>> = Array.from({ length: leftCount }, () => []);\nfor (const [left, right] of edges) {\n    adj[left].push(right);\n}\nconst matchRight = Array(rightCount).fill(-1);\nconst seen = Array(rightCount).fill(false);\nfunction dfs(left: number): boolean {\n    for (const right of adj[left]) {\n        if (seen[right]) {\n            continue;\n        }\n        seen[right] = true;\n        if (matchRight[right] === -1 || dfs(matchRight[right])) {\n            matchRight[right] = left;\n            return true;\n        }\n    }\n    return false;\n}\nlet matched = 0;\nfor (let left = 0; left < leftCount; left++) {\n    if (dfs(left)) {\n        matched++;\n    }\n}\nreturn matched;","lineMap":{"2":1,"3":2,"4":3,"6":5,"7":6,"10":8,"11":9,"12":10,"13":12,"14":13,"15":14,"16":15,"17":18,"19":20,"20":21,"21":22,"22":23,"23":26},"statementBundles":{"4":{"startLine":3,"endLine":4},"7":{"startLine":6,"endLine":7},"12":{"startLine":10,"endLine":11},"16":{"startLine":15,"endLine":17},"17":{"startLine":18,"endLine":19},"22":{"startLine":23,"endLine":25}}},"java":{"languageLabel":"Java","editorLanguage":"java","codeStyle":"natural","code":"private static boolean dfs(int left, List<List<Integer>> adj, List<Boolean> seen, List<Integer> matchRight) {\n    for (Integer right : adj.get(left)) {\n        if (seen.get(right)) {\n            continue;\n        }\n        seen.set(right, true);\n        if ((matchRight.get(right) == -1 || dfs(matchRight.get(right), adj, seen, matchRight))) {\n            matchRight.set(right, left);\n            return true;\n        }\n    }\n    return false;\n}\n\nList<List<Integer>> adj = new ArrayList<>();\nfor (int i = 0; i < leftCount; i++) {\n    adj.add(new ArrayList<>());\n}\nfor (List<Integer> edge : edges) {\n    int left = edge.get(0);\n    int right = edge.get(1);\n    adj.get(left).add(right);\n}\nList<Integer> matchRight = new ArrayList<>();\nfor (int index = 0; index < rightCount; index++) {\n    matchRight.add(-1);\n}\nList<Boolean> seen = new ArrayList<>();\nfor (int index = 0; index < rightCount; index++) {\n    seen.add(false);\n}\nint matched = 0;\nfor (int left = 0; left < leftCount; left++) {\n    if (dfs(left, adj, seen, matchRight)) {\n        matched++;\n    }\n}\nreturn matched;","lineMap":{"2":15,"3":19,"4":22,"6":24,"7":28,"10":2,"11":3,"12":4,"13":6,"14":7,"15":8,"16":9,"17":12,"19":32,"20":33,"21":34,"22":35,"23":38},"statementBundles":{"2":{"startLine":15,"endLine":18},"3":{"startLine":19,"endLine":21},"4":{"startLine":22,"endLine":23},"6":{"startLine":24,"endLine":27},"7":{"startLine":28,"endLine":31},"12":{"startLine":4,"endLine":5},"16":{"startLine":9,"endLine":11},"17":{"startLine":12,"endLine":13},"22":{"startLine":35,"endLine":37}}},"csharp":{"languageLabel":"C#","editorLanguage":"csharp","codeStyle":"natural","code":"List<List<int>> adj = Enumerable.Range(0, leftCount).Select(_ => new List<int>()).ToList();\nforeach (var item in edges) {\n    int left = item[0];\n    int right = item[1];\n    adj[left].Add(right);\n}\nList<int> matchRight = Enumerable.Repeat<int>(-1, rightCount).ToList();\nList<bool> seen = Enumerable.Repeat<bool>(false, rightCount).ToList();\nbool Dfs(int left) {\n    foreach (int right in adj[left]) {\n        if (seen[right]) {\n            continue;\n        }\n        seen[right] = true;\n        if (matchRight[right] == -1 || Dfs(matchRight[right])) {\n            matchRight[right] = left;\n            return true;\n        }\n    }\n    return false;\n    return false;\n}\nint matched = 0;\nfor (int left = 0; left < leftCount; left++) {\n    if (Dfs(left)) {\n        matched++;\n    }\n}\nreturn matched;","lineMap":{"2":1,"3":2,"4":5,"6":7,"7":8,"10":10,"11":11,"12":12,"13":14,"14":15,"15":16,"16":17,"17":20,"19":23,"20":24,"21":25,"22":26,"23":29},"statementBundles":{"3":{"startLine":2,"endLine":4},"4":{"startLine":5,"endLine":6},"7":{"startLine":8,"endLine":9},"12":{"startLine":12,"endLine":13},"16":{"startLine":17,"endLine":19},"17":{"startLine":20,"endLine":22},"22":{"startLine":26,"endLine":28}}},"cpp":{"languageLabel":"C++","editorLanguage":"cpp","codeStyle":"natural","code":"function<bool(int)> dfs;\n\nvector<vector<int>> adj = vector<vector<int>>(left_count, vector<int>{});\nfor (vector<int> item : edges) {\n    int left = item[0];\n    int right = item[1];\n    adj[left].push_back(right);\n}\nvector<int> match_right = vector<int>(right_count, -1);\nvector<bool> seen = vector<bool>(right_count, false);\ndfs = [&]( int left ) -> bool {\n    for (int right : adj[left]) {\n        if (seen[right]) {\n            continue;\n        }\n        seen[right] = true;\n        if ((match_right[right] == -1 || dfs(match_right[right]))) {\n            match_right[right] = left;\n            return true;\n        }\n    }\n    return false;\n};\nint matched = 0;\nfor (int left = 0; left < left_count; left++) {\n    if (dfs(left)) {\n        matched++;\n    }\n}\nreturn matched;","lineMap":{"2":3,"3":4,"4":7,"6":9,"7":10,"10":12,"11":13,"12":14,"13":16,"14":17,"15":18,"16":19,"17":22,"19":24,"20":25,"21":26,"22":27,"23":30},"statementBundles":{"3":{"startLine":4,"endLine":6},"4":{"startLine":7,"endLine":8},"7":{"startLine":10,"endLine":11},"12":{"startLine":14,"endLine":15},"16":{"startLine":19,"endLine":21},"17":{"startLine":22,"endLine":23},"22":{"startLine":27,"endLine":29}}}}}},{"id":"edge-case-intro","chapter":"Edge cases","kind":"info","eyebrow":"Try to break it","title":"Which inputs could break this?","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"graph","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"}],"edges":[["L0","R0"],["L1","R0"]]}}}]},"body":["Running one rerouting search per left node, with fresh seen state each time, paired both nodes in the sample.","Before coding it, push on the inputs that stress how the count is seeded and how far one right node's ownership can stretch."]},{"id":"no-edges-edge","chapter":"Edge cases","kind":"case-probe","eyebrow":"Stress the rule","title":"What if no edges exist at all?","summary":"leftCount = 3, rightCount = 2, and the edge list is empty.","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"graph","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"L2","label":"L2"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[]}}}]},"options":[{"id":"zero","label":"0, no pairing is possible","rationale":"Every left node's neighbor list is empty, so each search finds no right node to claim or reroute. The count never leaves zero.","isCorrect":true},{"id":"two","label":"2, capped by the smaller side","rationale":"The cap is an upper bound. With no edges there is nothing to pair, so the actual matching is zero.","isCorrect":false},{"id":"three","label":"3, one per left node","rationale":"A left node only counts when its search succeeds. With no edges, no search succeeds, so none of the three are matched.","isCorrect":false}],"answer":"0. Every neighbor list is empty, so no search can claim or reroute a right node and the count stays zero."},{"id":"chain-reroute-edge","chapter":"Edge cases","kind":"case-probe","eyebrow":"Stress the rule","title":"Three left nodes all want right 0 first. Can all three match?","summary":"leftCount = 3, rightCount = 3. Left 0 reaches right 0 and right 1, left 1 reaches right 0 and right 2, left 2 reaches only right 0.","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"graph","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"L2","label":"L2"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"},{"id":"R2","label":"R2"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"],["L1","R2"],["L2","R0"]]}}}]},"options":[{"id":"all-three","label":"Yes, a chain of relocations frees right 0 for left 2","rationale":"Left 2 needs right 0. The search asks left 0 to move to right 1, and left 1, if it held right 0, to move to right 2. Each owner has a spare, so the chain reaches free right nodes and all three match.","isCorrect":true},{"id":"two-only","label":"No, left 2 has only one edge, so it cannot match","rationale":"One edge is enough when the owner of that right node can relocate. Both earlier left nodes have spare right nodes, so the relocation chain clears right 0 for left 2.","isCorrect":false},{"id":"depends-order","label":"Only if the left nodes happen to be processed in a lucky order","rationale":"The rerouting search succeeds regardless of order, because it actively relocates owners rather than relying on them to have chosen well. The chain finds the free right nodes either way.","isCorrect":false}],"answer":"Yes. Left 2's search pushes left 0 toward right 1 and left 1 toward right 2, and since each owner has a spare, the chain frees right 0 and all three match."},{"id":"ready-to-code","chapter":"Code","kind":"info","eyebrow":"Get ready to code","title":"Turn the rerouting rule into code","summary":"Watch one detail: each left node's search needs its own fresh record of which right nodes it has touched.","ctaLabel":"Start coding","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"graph","state":{"graph":{"nodes":[{"id":"L0","label":"L0"},{"id":"L1","label":"L1"},{"id":"R0","label":"R0"},{"id":"R1","label":"R1"}],"edges":[["L0","R0"],["L0","R1"],["L1","R0"]]}}}]},"body":["Group each left node's right-side options into a neighbor list, and record for each right node which left node currently owns it. Then run a search from every left node: it takes a free right node, or asks the current owner to relocate down the owner's own edges.","Give each left node's search a fresh visited record so an earlier search's marks never hide a reroute, and count one for every search that succeeds."]},{"id":"coding","kind":"coding","source":"coding-checkpoints","chapter":"Code","title":"Build the rerouting matcher","eyebrow":"Code the rule","summary":"Now turn the rerouting idea into code: build each left node's neighbor list, define the search that claims a free right node or asks an owner to relocate, run it from every left node with fresh visited state, and count the searches that succeed.","workspacePanel":"code","checkpoints":[{"id":"build-adj","title":"Build adjacency","description":"Convert the edge list into neighbors for each left node.","commonMistakes":["Adding right nodes to the wrong left bucket","Treating edges as undirected"],"hint":"Each edge `[left, right]` should append `right` to `adj[left]`.","semanticSpec":{"intent":"Build the bipartite adjacency state.","doneWhen":"Every edge contributes a right-side neighbor under its left node.","shouldFailWhen":"This step should fail if the matching search has no adjacency state.","roles":["left node","right node","adjacency"],"mustProve":["Bipartite adjacency state is built."],"mustNotAccept":["A flat list with no left-to-right grouping."],"equivalentVariants":["Use arrays, lists, or maps for left-side buckets."]},"validation":{"type":"semantic","validator":"familyFact","params":[{"family":"bipartite-matching","fact":"builds_bipartite_adjacency_state","scope":"build-adj","readMode":"bipartite-matching-value-query-v1"}]}},{"id":"dfs-match","title":"Define augmenting DFS","description":"Create a helper that claims free right nodes or reroutes their current owners.","commonMistakes":["Only accepting currently free right nodes","Not marking right nodes as seen"],"hint":"If `right` is already matched, recursively search from its current owner.","semanticSpec":{"intent":"Define the augmenting-path reroute helper.","doneWhen":"The helper recurses through current right-side owners and updates matches when rerouting succeeds.","shouldFailWhen":"This step should fail if the helper is greedy and never reroutes.","roles":["left node","right node","match state"],"mustProve":["An augmenting reroute helper is defined."],"mustNotAccept":["A first-free-only greedy assignment."],"equivalentVariants":["Use DFS as an inner function or helper method."]},"validation":{"type":"semantic","validator":"familyFact","params":[{"family":"bipartite-matching","fact":"defines_augmenting_reroute_helper","scope":"dfs-match","readMode":"bipartite-matching-value-query-v1"}]}},{"id":"reset-seen","title":"Search with fresh seen state","description":"Run one augmenting DFS per left node with a new right-side seen array.","commonMistakes":["Reusing seen state across different left nodes","Never attempting unmatched left nodes"],"hint":"The seen array prevents cycles inside one DFS, but it must reset for the next root.","semanticSpec":{"intent":"Execute augmenting searches with fresh visited state.","doneWhen":"Each root search allocates fresh right-side visited state and calls the helper.","shouldFailWhen":"This step should fail if visited state is shared across root searches.","roles":["root left node","seen state","augmenting helper"],"mustProve":["Augmenting search executes with fresh visited state."],"mustNotAccept":["A global seen set shared by all root searches."],"equivalentVariants":["Use boolean arrays, sets, or equivalent per-search state."]},"validation":{"type":"semantic","validator":"familyFact","params":[{"family":"bipartite-matching","fact":"executes_augmenting_search_with_fresh_visited_state","scope":"reset-seen","readMode":"bipartite-matching-value-query-v1"}]}},{"id":"matching-answer","title":"Return matching size","description":"Count successful augmenting searches and return that count.","commonMistakes":["Returning the match array instead of its size","Counting attempted searches instead of successful ones"],"hint":"Only increment when DFS actually finds an augmenting path.","semanticSpec":{"intent":"Return the size of the maximum matching after augmenting search.","doneWhen":"The function returns the count of successful augmenting paths.","shouldFailWhen":"This step should fail if the returned count is unrelated to matching success.","roles":["matching count","augmenting success"],"mustProve":["The matching size is returned after augmenting search."],"mustNotAccept":["Returning the number of edges or left nodes."],"equivalentVariants":["Count successes directly or count filled right-side match entries."]},"validation":{"type":"semantic","validator":"familyFact","params":[{"family":"bipartite-matching","fact":"returns_matching_size_after_augmenting_search","scope":"matching-answer","readMode":"bipartite-matching-value-query-v1"}]}}]},{"id":"complete","kind":"complete","chapter":"Code","title":"You can see why rerouting wins","eyebrow":"Wrap up","summary":"Greedy stranded a pairing it could not undo; the rerouting search recovered it.","workspacePanel":"code","takeaways":[{"title":"Greedy never takes back a match","body":"One early grab of a shared right node can strand a later left node that had no spare."},{"title":"A chain of relocations grows the matching by exactly one","body":"A left node can still be added whenever a chain of relocations from its right nodes reaches a right node nobody owns."},{"title":"Each left node's search starts with a fresh visited record","body":"A right node marked by an earlier search would otherwise hide the very reroute a later search depends on."},{"title":"One search per left node costs O(L * E) time","body":"It uses O(L + R + E) space, and the matching can never exceed the smaller side."}],"nextAction":"Submit runs your solution against every test case."}],"slidesOrigin":"authored"},"starterFunctionName":"maximumBipartiteMatching","tags":["Graph","Bipartite Matching","Augmenting Path"]}
