To make sure the new directed graph is connected, I would use the first search in the following order.
old_undirected graph G new_directed graph D dequeue Q v is any node in G add v to D Q.push_back(v) while(Q is not empty): v = Q.pop_front() for all neighbors u to v: if u in D add edge u->v to D else add u to D and add edge v->u to D Q.push_back(u) return D
this graph must contain all the edges of the original graph, but must be directed so that there are no circles.
Bertil baron
source share