@@ -0,0 +1,729 @@
+package week1;%0A%0Aclass QuickUnionUF %7B%0A    private int%5B%5D id;%0A%0A    public QuickUnionUF(int n) %7B%0A        id = new int%5Bn%5D;%0A        for (int i = 0; i %3C n; i++) %7B%0A            id%5Bi%5D = i;%0A        %7D%0A    %7D%0A%0A    // Here we have a problem. What if our tree goes too tall?%0A    // In this case we'll do a lot of jumps to find the root and if we%0A    // have a lot of union request it would take significant time%0A    // to do.%0A    private int root(int i) %7B%0A        while(i != id%5Bi%5D) %7B%0A            i = id%5Bi%5D;%0A        %7D%0A        return i;%0A    %7D%0A%0A    private boolean connected(int p, int q) %7B%0A        return root(p) == root(q);%0A    %7D%0A%0A    public void union(int p, int q) %7B%0A        int i = root(p);%0A        int j = root(q);%0A        id%5Bi%5D = j;%0A    %7D%0A%7D%0A

implement quick union