/**
 * Tests the disjoint-set datastructure declared below on the two sample
 * inputs from the Kattis "unionfind" problem at [1].
 *
 * @author Elvis Stansvik <elvstone@gmail.com>
 *
 * [1] https://kth.kattis.com/problems/unionfind
 */
class DisjointSetsTest {
    public static void main(String[] args) {
        DisjointSets s1;
        DisjointSets s2;

        int r; // Unused.

        // First test case (unionfind1.in on Kattis).
        s1 = new DisjointSets();
        r = s1.init(10);
        r = s1.same(1, 3);
        r = s1.union(1, 8);
        r = s1.union(3, 8);
        r = s1.same(1, 3);

        // Second test case (unionfind2.in on Kattis).
        s2 = new DisjointSets();
        r = s2.init(4);
        r = s2.same(0, 0);
        r = s2.union(0, 1);
        r = s2.union(1, 2);
        r = s2.union(0, 2);
        r = s2.same(0, 3);
    }
}

/**
 * Disjoint-set data structure for non-negative integer elements.
 *
 * @author Elvis Stansvik <elvstone@gmail.com>
 *
 * [1] https://en.wikipedia.org/wiki/Disjoint-set_data_structure
 */
class DisjointSets {
    int[] parent;
    int[] rank;

    // Initialize the sets { {0}, {1}, ..., {N - 1} }.
    public int init(int N) {
        int i;
        parent = new int[N];
        rank = new int[N];
        i = 0;
        while (i < N) {
            parent[i] = i;
            i = i + 1;
        }
        return 0;
    }

    // Unions the subsets containing x and y.
    public int union(int x, int y) {
        int xRoot;
        int yRoot;
        xRoot = this.find(x);
        yRoot = this.find(y);

        if (xRoot != yRoot) {
            if (rank[xRoot] < rank[yRoot]) {
                parent[xRoot] = yRoot;
            } else {
                if (rank[xRoot] > rank[yRoot]) {
                    parent[yRoot] = xRoot;
                } else {
                    parent[yRoot] = xRoot;
                    rank[xRoot] = rank[xRoot] + 1;
                }
            }
        } else {
            // x and y already in same set.
        }

        return 0;
    }

    // Returns the representative for the subset containing x.
    public int find(int x) {
        int root;
        int next; // Used as temporary in second loop.

        // Find root.
        root = x;
        while (root != parent[root]) {
            root = parent[root];
        }

        // Re-parent all elements on path to root to root.
        while (x != root) {
            next = parent[x];
            parent[x] = root;
            x = next;
        }
        return root;
    }

    // Prints 1 if x and y is in the same subset, otherwise 0.
    public int same(int x, int y) {
        if (this.find(x) == this.find(y)) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
        return 0;
    }
}

@@ -1584,23 +1584,69 @@
  if 
+(!(!
 (xRoot 
+%3C yRoot) && !(yRoot %3C xRoot))) %7B // xRoot 
 != yRoot
 ) %7B%0A
@@ -1641,19 +1641,16 @@
 != yRoot
-) %7B
 %0A       
@@ -1776,23 +1776,23 @@
 ank%5B
-x
+y
 Root%5D 
-%3E
+%3C
  rank%5B
-y
+x
 Root
@@ -2311,16 +2311,19 @@
 ile 
+(!(!
 (root 
-!=
+%3C
  par
@@ -2329,25 +2329,77 @@
 rent%5Broot%5D) 
-%7B
+&& !(parent%5Broot%5D %3C root))) %7B // root != parent%5Broot%5D
 %0A           
@@ -2505,16 +2505,52 @@
  while (
+!(!(x %3C root) && !(root %3C x))) %7B // 
 x != roo
@@ -2550,19 +2550,16 @@
  != root
-) %7B
 %0A       
@@ -2783,42 +2783,167 @@
    i
-f (this.find(x) == this.find(y)) %7B
+nt xRoot;%0A        int yRoot;%0A        xRoot = this.find(x);%0A        yRoot = this.find(y);%0A%0A        if (!(xRoot %3C yRoot) && !(yRoot %3C xRoot)) %7B // xRoot == yRoot
 %0A   

Make test pure MiniJava.