def dfs_tree(G, source=None):
 T = nx.DiGraph()
 if (source is None):
  T.add_nodes_from(G)
 else:
  T.add_node(source)
 T.add_edges_from(dfs_edges(G, source))
 return T

def dfs_tree ( G , source = None ) : T = nx . DiGraph ( ) if ( source is None ) : T . add_nodes_from ( G ) else : T . add_node ( source ) T . add_edges_from ( dfs_edges ( G , source ) ) return T
return oriented tree constructed from a depth-first-search from source .