import networkx


def intersect_graphs(follow_graph, reply_graph):
    """
    Create a copy of the follow graph, but only keep edges where:
    (i replied to j) or (j replied to i), i.e. there is an edge in
    the reply graph between these two nodes in either direction.
    """

    G_intersection = networkx.DiGraph()

    # keep all nodes from the original follow graph
    G_intersection.add_nodes_from(follow_graph.nodes())

    for u, v in follow_graph.edges():
        if not reply_graph.has_edge(u, v) and not reply_graph.has_edge(v, u):
            continue

        G_intersection.add_edge(u, v)

    return G_intersection