old_contents: class StronglyConnectedComponents(object):
      def __init__(self):
          self.finishing_time = 1
          self.finishing_order = []
          self.reset_dfs_vars()
  
      def reset_dfs_vars(self):
          self.explored = set([])
          self.source_node = None
          self.components = {}
  
      def reverse_graph(self, graph):
          reversed_graph = {}
          for node in graph:
              edge_list = graph[node]
              for adj_node in edge_list:
                  try:
                      reversed_graph[adj_node].append(node)
                  except KeyError:
                      reversed_graph[adj_node] = [node]
  
          return reversed_graph
  
      def strongly_connected_components(self, graph):
          """
          Given a directed graph, return an array of its strongly connected components. A strongly connected component is a collection of nodes where each node is reachable from every other node.
  
          This implementation assumes the inputted graph is an adjacency list of nodes.
          """
          reversed_graph = self.reverse_graph(graph)
          for node in reversed_graph:
              if node not in self.explored:
                  self.dfs(reversed_graph, node)
  
          self.reset_dfs_vars()
          for node in reversed(self.finishing_order):
              if node not in self.explored:
                  self.source_node = node
                  self.dfs(graph, node)
  
          res = []
          for source_node in self.components:
              res.append(self.components[source_node])
          return res
  
      def dfs(self, graph, node):
          """
          Depth first search that:
          1. Updates the global variable finishing_order with order each node finished processing.
          2. Updates the global variable components, associating each node with the source node it was originally called from.
          """
          self.explored.add(node)
          try:
              self.components[self.source_node].append(node)
          except KeyError:
              self.components[self.source_node] = [node]
          for adj_node in graph[node]:
              if adj_node not in self.explored:
                  self.dfs(graph, adj_node)
  
          self.finishing_order.append(node)
          self.finishing_time += 1
  
new_contents: class StronglyConnectedComponents(object):
      def __init__(self):
          self.reset_dfs_vars()
  
      def reset_dfs_vars(self):
          self.finishing_time = 1
          self.finishing_order = []
          self.explored = set([])
          self.source_node = None
          self.components = {}
  
      def reverse_graph(self, graph):
          reversed_graph = {}
          for node in graph:
              edge_list = graph[node]
              for adj_node in edge_list:
                  try:
                      reversed_graph[adj_node].append(node)
                  except KeyError:
                      reversed_graph[adj_node] = [node]
  
          return reversed_graph
  
      def strongly_connected_components(self, graph):
          """
          Given a directed graph, return an array of its strongly connected components. A strongly connected component is a collection of nodes where each node is reachable from every other node.
  
          This implementation assumes the inputted graph is an adjacency list of nodes.
          """
          reversed_graph = self.reverse_graph(graph)
          for node in reversed_graph:
              if node not in self.explored:
                  self.dfs(reversed_graph, node)
          reversed_order = reversed(self.finishing_order)
          self.reset_dfs_vars()
  
          for node in reversed_order:
              if node not in self.explored:
                  self.source_node = node
                  self.dfs(graph, node)
  
          res = self.components.values()
          self.reset_dfs_vars()
          return res
  
      def dfs(self, graph, node):
          """
          Depth first search that:
          1. Updates the global variable finishing_order with order each node finished processing.
          2. Updates the global variable components, associating each node with the source node it was originally called from.
          """
          self.explored.add(node)
          try:
              self.components[self.source_node].append(node)
          except KeyError:
              self.components[self.source_node] = [node]
          for adj_node in graph[node]:
              if adj_node not in self.explored:
                  self.dfs(graph, adj_node)
  
          self.finishing_order.append(node)
          self.finishing_time += 1
  
subject: Update reset_dfs_vars