跳到正文

个人记录

观星

PigeonTree约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年2月26日
收录
2026年3月1日
更新
2026年11月11日
篇幅
约 1 分钟

版本

  1. v1当前

题目直通

题目思路

使用 Kruskal 求最小瓶颈生成树,很轻松可以求出 dd,在通过总存在的边和减去选用的边和即可。

Solution 函数

变量名就自行看了。

C++
void solution(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>x[i]>>y[i],fa[i]=i;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			tot++;
			p[tot]={i,j,abs(x[i]-x[j])+abs(y[i]-y[j])};
		}
	}
	sort(p+1,p+1+tot,cmp);
	int bs=0,maxn=-1;
	for(int i=1;i<=tot&&bs<=n-1;i++){
		int u=p[i].u,v=p[i].v,w=p[i].w;
		int fu=get(u),fv=get(v);
		if(fu!=fv){
			bs++;
			maxn=max(maxn,w);
			fa[fu]=fv;
			cho[i]=1;
		}
	}cout<<maxn<<" ";
	int cnt=0;
	for(int i=1;i<=tot;i++){
		if(p[i].w<=maxn&&!cho[i])cnt+=p[i].w;
	}cout<<cnt;
}
原文