Find the vertices of one component in a min-cut problem

algorithmsgraph theorynetwork-flow

I need to write a min-cut algorithm on a undirected graph, and retrieve the vertices of one of the components $S$ or $T$. I know some algorithms, like resolving the associated Max Flow problem or using Stoer Wagner. However, every example that I found of those algorithm return either the value of the min cut, or the edges by which passes the cut, that links into the "graphical" solution to find the vertices, cutting those edges in two and just observing the answer on a drawing of the graph.

However, I can't use such a graphical solution; my graph is a C++ structure that can be read either as an adjacency list or adjacency matrix.

Does an algorithm capable of returning the vertices of one of the two components of the cut exist? If so, where can I find an example on how to do this?

Thanks in advance.

Best Answer

Whenever you solve the max-flow problem using a residual graph (e.g. using the Ford-Fulkerson algorithm, or using push-relabel), the vertices you can reach from the source in the residual graph are the vertices on one side of the cut.

We can use this idea even if another method is used: starting from the source vertex, explore the graph by traveling forward along edges not at full capacity, and backward along edges with positive flow. The vertices you can reach in this way are exactly the vertices on one side of the cut.