def reverse_edge(G, edge, copy=False):
    """
    Reverse edge in graph.
    :param G: target graph
    :param edge: target edge
    :param copy: if True, copy graph before changing it
    :return: graph with reversed edge
    """
    if copy:
        G = G.copy()
    x, y = edge
    G.remove_edge(x, y)
    G.add_edge(y, x)
    return G