擅长:python、mysql、java
<p>你不需要一个后代列表,你只需要给他们上色。为此,您只需选择一个遍历图形的算法,并使用它为边上色。</p>
<p>例如,你可以</p>
<pre><code>from networkx.algorithms.traversal.depth_first_search import dfs_edges
G = DiGraph( ... )
for edge in dfs_edges(G, parent1):
color(edge)
</code></pre>
<p>见<a href="http://networkx.lanl.gov/reference/algorithms.traversal.html" rel="noreferrer">http://networkx.lanl.gov/reference/algorithms.traversal.html</a></p>