code: def _cuthill_mckee(vertices, vertices_neighbours):
      vertices_degrees = {v: sum(itervalues(vertices_neighbours[v]))
                          for v in vertices}
      peripheral_vertex = min(vertices, key=(lambda v: vertices_degrees[v]))
      visited = set([peripheral_vertex])
      cm_order = [peripheral_vertex]
      previous_layer = set([peripheral_vertex])
      while len(cm_order) < len(vertices):
          adjacent = set()
          for vertex in previous_layer:
              adjacent.update(vertices_neighbours[vertex])
          adjacent.difference_update(visited)
          visited.update(adjacent)
          cm_order.extend(sorted(adjacent, key=(lambda v: vertices_degrees[v])))
          previous_layer = adjacent
      return cm_order