def map_inv(succ):
    """Invert a multimap.
    Given a successor edge map, for example, produce an inverted
    predecessor edge map.
    """
    out = {key: [] for key in succ}
    for p, ss in succ.items():
        for s in ss:
            out[s].append(p)
    return out