Weighted quick-union with path compression for Ruby