class DisjointSet {
    private final int[] father;
    private final int[] rank;
    private final int N;
    private int numberOfComponents;

    DisjointSet(int N){
        this.N = N;
        rank = new int[N + 1];
        father = new int[N + 1];

        for (int i = 1; i <= N; i++)
            initialize(i);

        numberOfComponents = N;
    }

    void initialize(int node){
        if (!(1 <= node && node <= N)) throw new AssertionError();
        father[node] = node;
        rank[node] = 1;
    }

    int find(int node){
        if (!(1 <= node && node <= N)) throw new AssertionError();

        if (father[node] == node)
            return node;
        else
            return father[node] = find(father[node]);
    }

    void union(int x, int y){
        x = find(x);
        y = find(y);

        if (x != y){
            numberOfComponents--;

            if (rank[x] < rank[y])
                father[x] = y;
            else
                father[y] = x;

            if (rank[x] == rank[y])
                rank[x]++;
        }
    }

    boolean connected(int x, int y){
        return find(x) == find(y);
    }

    int getNumberOfComponents(){
        return numberOfComponents;
    }
}

@@ -75,16 +75,46 @@
 %5D rank;%0A
+    private final int%5B%5D size;%0A
     priv
@@ -274,16 +274,47 @@
 %5BN + 1%5D;
+%0A        size = new int%5BN + 1%5D;
 %0A%0A      
@@ -562,16 +562,40 @@
 e%5D = 1;%0A
+        size%5Bnode%5D = 1;%0A
     %7D%0A%0A 
@@ -812,24 +812,168 @@
 ode%5D);%0A    %7D
+%0A    %0A    int sizeComponent(int node)%7B%0A        if (!(1 %3C= node && node %3C= N)) throw new AssertionError();%0A        return size%5Bfind(node)%5D;%0A    %7D
 %0A%0A    void u
@@ -1117,32 +1117,34 @@
 nk%5Bx%5D %3C rank%5By%5D)
+ %7B
 %0A               
@@ -1159,16 +1159,66 @@
 x%5D = y;%0A
+                size%5By%5D += size%5Bx%5D;%0A            %7D%0A
         
@@ -1217,32 +1217,34 @@
             else
+ %7B
 %0A               
@@ -1259,16 +1259,78 @@
 y%5D = x;%0A
+                size%5Bx%5D += size%5By%5D;%0A            %7D%0A            
 %0A       

Update DisjointSet.java