每日一日:洛谷P1194 买礼物

链接:P1194 买礼物

思路:我们以0为起点来建立一棵最小生成树,那么肯定需要增加0到任意一个顶点的边,权值为A。最后这棵树总的权值即为答案

#include 
using namespace std;
int A,B;
struct edge{
	int start,to,val;
}bian[200007];
int f[200007];
int ans=0;
int find(int x){//并查集
	if(f[x]==x) return x;
	else return f[x]=find(f[x]);
}
bool cmp(edge a,edge b){
	return a.val>x;
			if(i==j||x==0||x>A||iA表示无意义,因为后面会额外增加一条以0为起点到任意顶点的边,i

你可能感兴趣的:(最小生产树,算法)