又是规律题,当时由于想大数的输入卡住了。。。没想到直接一个判断完事了
#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<