title: How to trace the path that visits all nodes in bfs/dfs
body: <p>This is similar to <a href="https://stackoverflow.com/questions/8922060/how-to-trace-the-path-in-a-breadth-first-search">How to trace the path in a Breadth-First Search?</a>, but the method described in the answers in that post doesn't work for my case, it seems.</p>
  
  <p>By path here, I essentially mean a sequence of connected nodes to get from a beginning to end state. </p>
  
  <p>Consider an undirected graph with vertices V={a,b,c} and edges = {{a,b},{a,c}}, and assume that we must traverse the successors alphabetically. We start at node <code>a</code> and the end state is to visit all 3 nodes. </p>
  
  <p>Breadth first search would first visit the edge <code>a-&gt;b</code>, and then the edge <code>a-&gt;c</code>. So the solution path is <code>a-&gt;b-&gt;a-&gt;c</code>. Since there is no edge between <code>b</code> &amp; <code>c</code>, we must go back through <code>a</code> (so we must traverse the edge <code>b-&gt;a</code>). In the answer in the above linked post, the accepted solution would only output <code>a-&gt;c</code>. </p>
  
  <p>I can't think of a way to modify the conventional bfs algorithm to do this. I have the same question for dfs, but I'd like to start with bfs for now. </p>