code: def topological_sort(self):
          graph = self.graph
          in_degree = {}
          for u in graph:
              in_degree[u] = 0
          for u in graph:
              for v in graph[u]:
                  in_degree[v] += 1
          queue = deque()
          for u in in_degree:
              if in_degree[u] == 0:
                  queue.appendleft(u)
          sorted_graph = []
          while queue:
              u = queue.pop()
              sorted_graph.append(u)
              for v in sorted(graph[u]):
                  in_degree[v] -= 1
                  if in_degree[v] == 0:
                      queue.appendleft(v)
          if len(sorted_graph) == len(graph):
              return sorted_graph
          else:
              raise ValueError('graph is not acyclic')