def robust_topological_sort(graph: Graph) -> list:
assert check_argument_types()<EOL>components = strongly_connected_components(graph)<EOL>node_component = {}<EOL>for component in components:<EOL><INDENT>for node in component:<EOL><INDENT>node_component[node] = component<EOL><DEDENT><DEDENT>component_graph = {}<EOL>for component in components:<EOL><INDENT>component_graph[component] = []<EOL><DEDENT>for node in graph:<EOL><INDENT>node_c = node_component[node]<EOL>for successor in graph[node]:<EOL><INDENT>successor_c = node_component[successor]<EOL>if node_c != successor_c:<EOL><INDENT>component_graph[node_c].append(successor_c) <EOL><DEDENT><DEDENT><DEDENT>return topological_sort(component_graph)<EOL>
Identify strongly connected components then perform a topological sort of those components.