bzoj2429(MST,最小瓶颈生成树)

实际就是求,图的生成树中最大边最小

实际上还是最小瓶颈生成树


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,t[505],tot;
int x[1055],y[1055],fa[1055];
struct aa
{
	int x,y;
	double dis;
	bool operator <(const aa &b) const
	{
		return dis<b.dis;
	}
}bian[1000005];

int find(int x)
{
	return fa[x]==x ? x : fa[x]=find(fa[x]); 
}

int main()
{
	scanf("%d",&m);
	for (int i=1;i<=m;i++) scanf("%d",&t[i]);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
	
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
		{
			double 
			dis=sqrt((x[i]-x[j])*(x[i]-x[j])*1.0+(y[i]-y[j])*(y[i]-y[j])*1.0);
			bian[++tot].x=i;bian[tot].y=j;bian[tot].dis=dis;
		}
	
	sort(bian+1,bian+tot+1);
	
	for (int i=1;i<=n;i++) fa[i]=i;
	
	int j=0,kk;
	for (int i=1;i<=tot;i++)
	{
		int fx=find(bian[i].x);
		int fy=find(bian[i].y);
		if (fx==fy) continue;
		else
		{
			j++;
			fa[fx]=fy;
			if (j==n-1)
			{
				kk=bian[i].dis;
				break;
			}
		}
	}
	int ans=0;
	for (int i=1;i<=m;i++)
	if (t[i]>=kk) ans++;
	
	printf("%d",ans);
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值