code: def shrink_to_node(self, scc):
          
          assert not self.final, 'Trying to mutate a final graph.'
          self.graph.add_node(scc)
          edges = list(self.graph.edges)
          for k, v in edges:
              if k not in scc and v in scc:
                  self.graph.remove_edge(k, v)
                  self.graph.add_edge(k, scc)
              elif k in scc and v not in scc:
                  self.graph.remove_edge(k, v)
                  self.graph.add_edge(scc, v)
          for node in scc.nodes:
              self.graph.remove_node(node)
docs: Shrink a strongly connected component into a node.