Weighted quick union algorithm with path compression for Ruby