8 Feb
2012
8 Feb
'12
6:17 p.m.
On Wed, 8 Feb 2012, NsPx wrote:
Hi all,
I use undirected_dfs to detect all cycles in a undirected graph. I detect a cycle with DFSVisitor.back_edge(e,g) but how can I get the list of vertices defining this cycle ?
Keep a predecessor map using predecessor_recorder, then walk the chain of predecessors from the target of the back_edge to its source. The vertices you iterate through are your cycle. Reading http://www.me.utexas.edu/~bard/IP/Handouts/cycles.pdf gives the algorithm and why it works in more detail. -- Jeremiah Willcock