import copy


def set_of_interest(trees_to_equality, trees_to_equality_N):
    """
    Inputs:
    trees_to_equality --- a mapping of tree strings to a set of other trees with the same p(gt|st)
    trees_to_equality_N --- a mapping of tree strings to a set of other trees with the same p(gt|N)
    Output:
    trees_of_interest --- a set of trees that changed equality under the species network
    """

    trees_of_interest = set([])

    for tree in trees_to_equality:

        if tree not in trees_to_equality_N:
            t_set = copy.deepcopy(trees_to_equality[tree])
            t_set.add(tree)
            trees_of_interest = trees_of_interest.union(t_set)
        elif trees_to_equality[tree] != trees_to_equality_N[tree]:
            t_set = copy.deepcopy(trees_to_equality[tree])
            t_set.add(tree)
            trees_of_interest = trees_of_interest.union(t_set)

    return trees_of_interest