code: def sorted_bfs_successors(G, source=None):
      if source is None:
          source = G.root
      successors = defaultdict(list)
      for src, target in sorted_bfs_edges(G, source):
          successors[src].append(target)
      return dict(successors)