def target_to_source(target_adjacency, embedding):
    source_adjacency = {v: set() for v in embedding}
    reverse_embedding = {}
    for v, chain in iteritems(embedding):
        for u in chain:
            if u in reverse_embedding:
                raise ValueError("target node {} assigned to more than one source node".format(u))
            reverse_embedding[u] = v
    for v, n in iteritems(reverse_embedding):
        neighbors = target_adjacency[v]
        for u in neighbors:
            if u not in reverse_embedding:
                continue
            m = reverse_embedding[u]
            if m == n:
                continue
            source_adjacency[n].add(m)
            source_adjacency[m].add(n)
    return source_adjacency