def reverse(graph):
    """replace all arcs (u, v) by arcs (v, u) in a graph"""
    rev_graph = [[] for node in graph]
    for node in range(len(graph)):
        for neighbor in graph[node]:
            rev_graph[neighbor].append(node)
    return rev_graph
replace all arcs (u, v) by arcs (v, u) in a graph