def graphs_equal(graph1, graph2):
    """Returns whether two NetworkX graphs (directed or undirected) are equal."""
    if not graph1.order() == graph2.order() or not graph1.size(
        ) == graph2.size():
        return False
    for u, v in graph1.edges():
        if not graph2.has_edge(u, v):
            return False
    return True
