B Build Roads大数规律题,最小生成树

这是一篇关于B Build Roads的博客,主要探讨了题目中的大数规律及其与最小生成树的关联。作者指出,解决此类问题的关键并不在于复杂的大数输入处理,而是一个简洁的判断策略。
摘要由CSDN通过智能技术生成

又是规律题,当时由于想大数的输入卡住了。。。没想到直接一个判断完事了

#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define ll unsigned long long
using namespace std;
const int maxn=1e7+9;
int n,L,R,a[200001];
ll seed;
int tot=0;
ll xors()
{
	ll x=seed;
	x^=x<<13;
	x^=x>>7;
	x^=x<<17;
	return seed=x;
}
int gen()
{
	return xors()%(R-L+1)+L;
}
int gcd(int a,int b)
{
	if (b)
		return gcd(b,a%b);
	return a;
}
int fa[maxn];
struct node
{
	int u,v,w;
} edge[maxn];
bool cmp(node a,node b)
{
	return a.w<b.w;
}
//并查集判断环路
int find(int x)
{
	if (fa[x]==-1)
//本来应该初始化fa[]数组,然后fa[x]=x时return x,这样写效果一样 
		return x;
	return fa[x]=find(fa[x]);
}
long long kruskal(int n)
{
	int i,j;
	memset(fa,-1,sizeof(fa));
	sort(edge+1,edge+1+tot,cmp);
//最小生成树是把边从小到大排序后拿出来建边,所以要排序。

	int cnt=0;
	long long ans=0;
	for (i=1; i<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值