code: def connected_components(G):
      
      result = []
      vertices = set(G.vertices)
      while vertices:
          n = vertices.pop()
          group = {n}
          queue = Queue()
          queue.put(n)
          while not queue.empty():
              n = queue.get()
              neighbors = set(G.vertices[n])
              neighbors.difference_update(group)
              vertices.difference_update(neighbors)
              group.update(neighbors)
              for element in neighbors:
                  queue.put(element)
          result.append(group)
      return result
docs: Check if G is connected and return list of sets. Every
      set contains all vertices in one connected component.