private static int follow(int i, int[] partitions) {
    int next = partitions[i], tmp;
    while(i != next) {
      tmp = next;
      next = partitions[i] = partitions[next];
      i = tmp;
    }
    return i;
  }
private static int follow ( int i , int [ ] partitions ) { int next = partitions [ i ] , tmp ; while ( i != next ) { tmp = next ; next = partitions [ i ] = partitions [ next ] ; i = tmp ; } return i ; }
Union-find with simple path compression.

@param i Start
@param partitions Partitions array
@return Partition