Skip to content

Commit 3f85008

Browse files
committed
docs: added comments for max flow ford fulkerson
1 parent 211acd1 commit 3f85008

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

SourceCodes/0003_Graph/0015_MaximumFlowFordFulkerson.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ namespace MaximumFlowFordFulkerson
2323

2424
this->_flagParallelEdges = countParallelEdges > 0;
2525

26+
// If there are no anti-parallel edges, no need to modify the adjMatrix
2627
if (!this->_flagParallelEdges)
2728
{
2829
return;
2930
}
3031

3132
int newNoOfVertices = this->_noOfVertices + countParallelEdges;
33+
34+
// Modifying the adjMatrix
3235
for (auto& edge : this->_adjMatrix)
3336
{
3437
edge.resize(newNoOfVertices, 0);
@@ -38,6 +41,7 @@ namespace MaximumFlowFordFulkerson
3841
this->_parent.resize(newNoOfVertices, -1);
3942
this->_adjMatrix.resize(newNoOfVertices, vector<int>(newNoOfVertices, 0));
4043

44+
// Removing the anti-parallel edges by adding new nodes
4145
for (int i = 0; i < this->_noOfVertices; i++)
4246
{
4347
for (int j = 0; j < this->_noOfVertices; j++)
@@ -52,6 +56,7 @@ namespace MaximumFlowFordFulkerson
5256
}
5357
}
5458

59+
// Updating the total no of vertices after modifying the adjMatrix
5560
this->_noOfVertices = newNoOfVertices;
5661
}
5762

@@ -70,9 +75,16 @@ namespace MaximumFlowFordFulkerson
7075

7176
bool Graph::DepthFirstSearch()
7277
{
78+
// Resetting the visited values
7379
fill(this->_visited.begin(), this->_visited.end(), false);
80+
81+
// Resetting the parent values
7482
fill(this->_parent.begin(), this->_parent.end(), -1);
83+
84+
// Starting the DepthFirstSearch from the source vertex
7585
this->DepthFirstSearchVisit(this->_source);
86+
87+
// Returning the visited value of the sink vertex, initially it was set to false
7688
return this->_visited[this->_sink];
7789
}
7890

0 commit comments

Comments
 (0)