adding weighted quick union with path compression