static class Graph{

    private static class Edge{
        int node;
        int next;

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

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

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

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

        System.gc();

        this.N = N;
        this.contor = 0;

        for (int i = 0; i < N; ++i)
            head[i] = NIL;
    }

    void addEdge(int x, int y){
        x--; y--;
        graph.add(new Edge(y, head[x]));
        head[x] = contor++;
    }

    int getHead(int node){
        node--;
        return head[node];
    }

    int getNext(int p){
        assert 0 <= p && p < contor;
        return graph.get(p).next;
    }

    int getNeighbour(int p){
        assert 0 <= p && p < contor;
        return graph.get(p).node + 1;
    }
    
    int getN(){
        return N;
    }
}

@@ -1,19 +1,12 @@
-static 
 class Graph%7B
@@ -6,17 +6,16 @@
  Graph%7B%0A
-%0A
     priv
@@ -193,15 +193,8 @@
     
-public 
 fina
@@ -313,26 +313,23 @@
 e int co
+u
 nt
-o
+e
 r;%0A
-    
 %0A    Gra
@@ -364,28 +364,89 @@
 e(N);%0A    %7D%0A
-%0A
    
+ %0A    public int getN() %7B%0A        return N;%0A    %7D%0A%0A    private
  void initia
@@ -531,30 +531,8 @@
 );%0A%0A
-        System.gc();%0A%0A
     
@@ -562,19 +562,20 @@
  this.co
+u
 nt
-o
+e
 r = 0;%0A%0A
@@ -586,61 +586,30 @@
     
-for (int i = 0; i %3C N; ++i)%0A            head%5Bi%5D =
+Arrays.fill(head,
  NIL
+)
 ;%0A  
@@ -645,16 +645,49 @@
 int y)%7B%0A
+        assert 1 %3C= x && x %3C= N;%0A
         
@@ -757,19 +757,20 @@
 %5Bx%5D = co
+u
 nt
-o
+e
 r++;%0A   
@@ -800,16 +800,55 @@
  node)%7B%0A
+        assert 1 %3C= node && node %3C= N;%0A
         
@@ -936,35 +936,36 @@
 0 %3C= p && p %3C co
+u
 nt
-o
+e
 r;%0A        retur
@@ -1056,11 +1056,12 @@
 %3C co
+u
 nt
-o
+e
 r;%0A 
@@ -1107,51 +1107,6 @@
   %7D%0A
-    %0A    int getN()%7B%0A        return N;%0A    %7D%0A
 %7D%0A

Update Graph.java