Weighted trees implementation