def invert_cd_path(graph, path, c, d):
    """
    Switch the colors of the edges on the cd-path: c to d and d to c.
    :param graph: nx.Graph(); each edge should have an attribute "color"
    :param path: nx.Graph() representing cd-path
    :param c: integer smaller then the degree of "graph" or None; represents a color
    :param d: integer smaller then the degree of "graph" or None; represents a color
    :return: graph with switched colors
    """
    for edge in path.edges:
        current_color = graph.get_edge_data(*edge)["color"]
        if current_color == c:
            graph.add_edge(*edge, color=d)
        if current_color == d:
            graph.add_edge(*edge, color=c)

    return graph