def parse2dot(parse):
    """
    makes a dot-readable string of nodes and edges

    Arguments
    parse : a parse of the string of the form (bigrams,_,(states visited, operations used),_)

    Returns
    nodes and edges where nodes are pairs of unique names and labels, and edges are pairs of nodes
    """
    (bis,buf,(qs,ops),k)=parse
    nodes=[]
    edges=[]
    n=0 # for naming nodes uniquely
    i=1 # for moving through the bigrams
    for q,op in zip(qs[:-2],ops[:-1]):
        nodes.append((n,q)) # mother node
        if op=='mg': # if it's merge, let's get the word too
            left = "mg\n%s"%bis[i]
            i+=1
        else:
            left=op
        nodes.append((n+1,left)) # left daughter is lexical
        edges.append((n,n+1)) # edge to left daughter
        edges.append((n,n+2)) # edge to right daughter
        n+=2 # right daughter is the new mother node

    nodes.append((n,qs[-2])) # the last constituent is unary-branching
    nodes.append((n+1,ops[-1]))
    edges.append((n,n+1))

    return nodes,edges