def get_halfs(self, vertex1, vertex2):
def grow(origin, other):<EOL><INDENT>frontier = set(self.neighbors[origin])<EOL>frontier.discard(other)<EOL>result = set([origin])<EOL>while len(frontier) > <NUM_LIT:0>:<EOL><INDENT>pivot = frontier.pop()<EOL>if pivot == other:<EOL><INDENT>raise GraphError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>pivot_neighbors = set(self.neighbors[pivot])<EOL>pivot_neighbors -= result<EOL>frontier |= pivot_neighbors<EOL>result.add(pivot)<EOL><DEDENT>return result<EOL><DEDENT>vertex1_part = grow(vertex1, vertex2)<EOL>vertex2_part = grow(vertex2, vertex1)<EOL>return vertex1_part, vertex2_part<EOL>
Split the graph in two halfs by cutting the edge: vertex1-vertex2

           If this is not possible (due to loops connecting both ends), a
           GraphError is raised.

           Returns the vertices in both halfs.