Weighted Union find algorithm