#include<bits/stdc++.h>
using namespace std;
const int N=100001;
const int MOD=1e9+7;
unsigned long long k1,k2;
unsigned long long xorShift128Plus(){
unsigned long long k3=k1,k4=k2;
k1=k4;
k3^=k3<<23;
k2=k3^k4^(k3>>17)^(k4>>26);
return k2+k4;
}
struct edge{
int u,v;
unsigned long long w;
bool operator < (const edge &x)const {
return w<x.w;
}
}e[100001];
int p[N];
int find(int x){
if(p[x]!=x)p[x]=find(p[x]);
return p[x];
}
int n,m;
void gen(){
scanf("%d%d%llu%llu",&n,&m,&k1,&k2);
for(int i=1;i<=m;++i){
e[i].u=xorShift128Plus()%n+1;
e[i].v=xorShift128Plus()%n+1;
e[i].w=xorShift128Plus();
//cout<<e[i].u<<" "<<e[i].v<<" "<<e[i].w<<endl;
}
}
int main(){
int t;
scanf("%d",&t);
while(t--){
gen();
sort(e+1,e+1+m);
for(int i=1;i<=n;++i) p[i]=i;
int cnt=0;
unsigned long long res=0;
for(int i=1;i<=m;++i){
int a=e[i].u,b=e[i].v;
unsigned long long w=e[i].w;
a=find(a),b=find(b);
if(a!=b){
p[a]=b;
res=(res+w)%MOD;
cnt++;
}
}
if(cnt<n-1)puts("0");
else cout<<res%MOD<<"\n";
}
}
注意:
1. 题目中给的代码片段是一种生成伪随机数的算法,Wikipedia上可以查到。
相关介绍
What is the real definition of the xorshift128+ algorithm?
关键是,这个算法
通过异或和位移 , 每次生成不同的32位, 周期为2的32次方减1。
也就是没有权重相等的边。
也就是最小生成树如果有的话只有一个。
比赛时如果看不懂这个算法怎么生成随机数的,打个表也能猜出来没重边。
徐州场的签到题。