class Graph{
    private static class Edge{
        int node;
        int next;

        Edge(int node, int next){
            this.node = node;
            this.next = next;
        }
    }

    final static int NIL = -1;
    private int[] head;
    private int[] degree;
    private ArrayList<Edge> graph;

    private int N;
    private int counter;

    Graph(int N){
        initialize(N);
    }

    public int getN() {
        return N;
    }

    private void initialize(final int N){
        head = new int[N];
        degree = new int[N];
        graph = new ArrayList<>();

        this.N = N;
        this.counter = 0;

        Arrays.fill(head, NIL);
        Arrays.fill(degree, 0);
    }

    void addEdge(int x, int y){
        if (!(1 <= x && x <= N)) throw new AssertionError();
        x--; y--;
        graph.add(new Edge(y, head[x]));
        head[x] = counter++;
        degree[x]++;
    }

    int getHead(int node){
        if (!(1 <= node && node <= N)) throw new AssertionError();
        node--;
        return head[node];
    }

    int getNext(int p){
        if (!(0 <= p && p < counter)) throw new AssertionError();
        return graph.get(p).next;
    }

    int getNeighbour(int p){
        if (!(0 <= p && p < counter)) throw new AssertionError();
        return graph.get(p).node + 1;
    }

    boolean isEmpty(int node){
        if (!(1 <= node && node <= N)) throw new AssertionError();
        node--;
        return head[node] == NIL;
    }

    int size(int node){
        assert 1 <= node && node <= N;
        node--;
        return degree[node];
    }
}

@@ -1588,11 +1588,541 @@
 %5D;%0A    %7D
+%0A%0A    Graph transpose()%7B%0A        Graph GT = new Graph(N);%0A%0A        for (int i = 1; i %3C= N; i++) %7B%0A            for (int son : getNeighbours(i))%0A                GT.addEdge(son, i);%0A        %7D%0A%0A        return GT;%0A    %7D%0A%0A    List%3CInteger%3E getNeighbours(int node)%7B%0A        if (!(1 %3C= node && node %3C= N)) throw new AssertionError();%0A%0A        List%3CInteger%3E list = new ArrayList%3C%3E();%0A%0A        for (int p = head%5Bnode - 1%5D; p != NIL; p = graph.get(p).next) %7B%0A            list.add(graph.get(p).node + 1);%0A        %7D%0A%0A        return list;%0A    %7D
 %0A%7D%0A

Update Graph.java