def SCC(G): G = DFS(G) L = [(u[0], u[1]['f']) for u in G.nodes(data=True)] L.sort(key=lambda x: -x[1]) L = [x[0] for x in L] H = transpose(G) # DFS the G^T in decreasing finish time for n in H.nodes(data=True): n[1]['c'] = 0 n[1]['d'] = float('inf') n[1]['f'] = 0 n[1]['p'] = None time = 0 for n in L: if H.node[n]['c'] == 0: DFS_VISIT(H, n) return H
def SCC(G): G = DFS(G) L = [ (u[0],u[1]['f']) for u in G.nodes(data=True) ] L.sort(key=lambda x: -x[1]) L = [ x[0] for x in L ] H = transpose(G) # DFS the G^T in decreasing finish time for n in H.nodes(data=True): n[1]['c'] = 0 n[1]['d'] = float('inf') n[1]['f'] = 0 n[1]['p'] = None time = 0 for n in L: if H.node[n]['c'] == 0: DFS_VISIT(H, n) return H
def topological_sort(G): G = DFS(G) L = [(u[0], u[1]['f']) for u in G.nodes(data=True)] L.sort(key=lambda x: -x[1]) return [x[0] for x in L]
def topological_sort(G): G = DFS(G) L = [ (u[0],u[1]['f']) for u in G.nodes(data=True) ] L.sort(key=lambda x: -x[1]) return [ x[0] for x in L ]