@@ -23,12 +23,15 @@ namespace MaximumFlowFordFulkerson
23
23
24
24
this ->_flagParallelEdges = countParallelEdges > 0 ;
25
25
26
+ // If there are no anti-parallel edges, no need to modify the adjMatrix
26
27
if (!this ->_flagParallelEdges )
27
28
{
28
29
return ;
29
30
}
30
31
31
32
int newNoOfVertices = this ->_noOfVertices + countParallelEdges;
33
+
34
+ // Modifying the adjMatrix
32
35
for (auto & edge : this ->_adjMatrix )
33
36
{
34
37
edge.resize (newNoOfVertices, 0 );
@@ -38,6 +41,7 @@ namespace MaximumFlowFordFulkerson
38
41
this ->_parent .resize (newNoOfVertices, -1 );
39
42
this ->_adjMatrix .resize (newNoOfVertices, vector<int >(newNoOfVertices, 0 ));
40
43
44
+ // Removing the anti-parallel edges by adding new nodes
41
45
for (int i = 0 ; i < this ->_noOfVertices ; i++)
42
46
{
43
47
for (int j = 0 ; j < this ->_noOfVertices ; j++)
@@ -52,6 +56,7 @@ namespace MaximumFlowFordFulkerson
52
56
}
53
57
}
54
58
59
+ // Updating the total no of vertices after modifying the adjMatrix
55
60
this ->_noOfVertices = newNoOfVertices;
56
61
}
57
62
@@ -70,9 +75,16 @@ namespace MaximumFlowFordFulkerson
70
75
71
76
bool Graph::DepthFirstSearch ()
72
77
{
78
+ // Resetting the visited values
73
79
fill (this ->_visited .begin (), this ->_visited .end (), false );
80
+
81
+ // Resetting the parent values
74
82
fill (this ->_parent .begin (), this ->_parent .end (), -1 );
83
+
84
+ // Starting the DepthFirstSearch from the source vertex
75
85
this ->DepthFirstSearchVisit (this ->_source );
86
+
87
+ // Returning the visited value of the sink vertex, initially it was set to false
76
88
return this ->_visited [this ->_sink ];
77
89
}
78
90
0 commit comments