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 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];
        graph = new ArrayList<>();

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

        Arrays.fill(head, NIL);
    }

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

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

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

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

@@ -240,16 +240,42 @@
 %5D head;%0A
+    private int%5B%5D degree;%0A
     priv
@@ -301,16 +301,16 @@
  graph;%0A
-
 %0A    pri
@@ -398,13 +398,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -513,16 +513,45 @@
 int%5BN%5D;%0A
+        degree = new int%5BN%5D;%0A
         
@@ -657,16 +657,48 @@
 , NIL);%0A
+        Arrays.fill(degree, 0);%0A
     %7D%0A%0A 
@@ -732,31 +732,30 @@
 y)%7B%0A        
-assert 
+if (!(
 1 %3C= x && x 
@@ -754,24 +754,53 @@
  x && x %3C= N
+)) throw new AssertionError()
 ;%0A        x-
@@ -877,16 +877,37 @@
 nter++;%0A
+        degree%5Bx%5D++;%0A
     %7D%0A%0A 
@@ -940,23 +940,22 @@
         
-assert 
+if (!(
 1 %3C= nod
@@ -968,16 +968,45 @@
 ode %3C= N
+)) throw new AssertionError()
 ;%0A      
@@ -1073,39 +1073,38 @@
 int p)%7B%0A        
-assert 
+if (!(
 0 %3C= p && p %3C co
@@ -1100,32 +1100,61 @@
 p && p %3C counter
+)) throw new AssertionError()
 ;%0A        return
@@ -1221,15 +1221,14 @@
     
-assert 
+if (!(
 0 %3C=
@@ -1244,16 +1244,45 @@
  counter
+)) throw new AssertionError()
 ;%0A      
@@ -1318,11 +1318,281 @@
 1;%0A    %7D
+%0A%0A    boolean isEmpty(int node)%7B%0A        if (!(1 %3C= node && node %3C= N)) throw new AssertionError();%0A        node--;%0A        return head%5Bnode%5D == NIL;%0A    %7D%0A%0A    int size(int node)%7B%0A        assert 1 %3C= node && node %3C= N;%0A        node--;%0A        return degree%5Bnode%5D;%0A    %7D
 %0A%7D%0A

Update Graph.java