Implement tree-dist

Also: refactor regular min-dist function over size and dist function.