问题
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/532604aa2f3094fc0379dc8cd31ea631.png)
解析
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cbf15d36d396760a137efcef135e056a.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c108b6d58d825e3c5aca30baaddde773.png)
设计
void create(){
for (int i = n; i < total; ++i) {
selectMin(tree, i - 1);
tree[s1].parent = tree[s2].parent = tree[i];
tree[i].left = tree[s1];
tree[i].right = tree[s2];
tree[i].weight = tree[s1].weight + tree[s2].weight;
}
}
分析
时间复杂度:O(nlogn)
源码
Github