docs: def add_edge(self, edge):
          """
          Add edge (u, v) to the graph. Raises InvariantError if adding the edge
          would form a cycle.
          """
          u, v = edge
  
          both_exist = u in self.vertices and v in self.vertices
          # Using `is` because if they belong to the same component, they MUST
          # share the same set object!
          if both_exist and self.components[u] is self.components[v]:
              # Both vertices are part of the same connected component.
              raise InvariantError('Adding %r would form a cycle' % (edge,))
          if u == v:
              raise InvariantError('Cannot add loop: %r' % (edge,))
  
          # Ensure the vertices exist in the graph.
          self.add_vertex(u)
          self.add_vertex(v)
  
          # Add the edges to each other.
          self._vertices[u].add(v)
          self._vertices[v].add(u)
  
          # Add all of the smaller components to the bigger one.
          smaller_component, bigger_component = self.sort_components(u, v)
          for vertex in smaller_component:
              bigger_component.add(vertex)
              # And with this assignment, say bye-bye to the smaller component.
              self.components[vertex] = bigger_component