@Test public void find() { UnionFind uf = new UnionFind(100); uf.union(1, 5); uf.union(7, 9); uf.union(10, 11); uf.union(15, 1); uf.union(15, 50); assertThat(uf.find(1), is(50)); assertThat(uf.find(5), is(50)); assertThat(uf.find(7), is(7)); assertThat(uf.find(8), is(8)); assertThat(uf.find(10), is(10)); assertThat(uf.find(11), is(10)); assertThat(uf.find(15), is(50)); assertThat(uf.find(50), is(50)); }
int find(int u) { return forest[u] < 0 ? u : (forest[u] = find(forest[u])); }
UnionFind { int find(int u) { return forest[u] < 0 ? u : (forest[u] = find(forest[u])); } }
UnionFind { int find(int u) { return forest[u] < 0 ? u : (forest[u] = find(forest[u])); } UnionFind(int n); }
UnionFind { int find(int u) { return forest[u] < 0 ? u : (forest[u] = find(forest[u])); } UnionFind(int n);  }
UnionFind { int find(int u) { return forest[u] < 0 ? u : (forest[u] = find(forest[u])); } UnionFind(int n);   }