Skip to content

Commit a9936c7

Browse files
committed
Update HopcroftKarp.cs
1 parent 5e2d8f7 commit a9936c7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Advanced.Algorithms/Graph/Matching/HopcroftKarp.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ private List<T> bfs(IGraph<T> graph,
8181
foreach (var vertex in partitions[1])
8282
{
8383
//if this left vertex is free
84-
if (!leftToRightMatchEdges.ContainsKey(vertex))
84+
if (!leftToRightMatchEdges.ContainsKey(vertex) && !visited.Contains(vertex))
8585
{
8686
queue.Enqueue(vertex);
87-
visited.Add(vertex);
88-
87+
8988
while (queue.Count > 0)
9089
{
9190
var current = queue.Dequeue();
91+
visited.Add(vertex);
9292

9393
//unmatched edges left to right
9494
foreach (var leftToRightEdge in graph.GetVertex(current).Edges)

0 commit comments

Comments
 (0)