UnionFind { boolean connected(int u, int v) { return find(u) == find(v); } UnionFind(int n);   }
@Test public void connected() { UnionFind uf = new UnionFind(100); uf.union(1, 5); uf.union(7, 9); uf.union(7, 5); uf.union(10, 11); uf.union(11, 50); uf.union(15, 1); uf.union(15, 50); assertTrue(uf.connected(1, 5)); assertTrue(uf.connected(1, 7)); assertTrue(uf.connected(1, 9)); assertTrue(uf.connected(1, 10)); assertTrue(uf.connected(1, 11)); assertTrue(uf.connected(1, 15)); assertTrue(uf.connected(1, 50)); }