QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#656847#7003. Rikka with Minimum Spanning TreesFork512HzWA 1211ms6400kbC++201.7kb2024-10-19 13:46:462024-10-19 13:46:50

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 13:46:50]
  • 评测
  • 测评结果:WA
  • 用时:1211ms
  • 内存:6400kb
  • [2024-10-19 13:46:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
//typedef long long ll;
unsigned long long k1 , k2;
//typedef pair<ll, ll> pii;
const ull M = 1000000007;
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;
}
ull n, m, u , v, w;
struct edge
{
	ull w, x, y;	
	edge(){
		
	}
	edge(ull p, ull q, ull r)
	{
		w=p, x=q, y=r;
	}
};
//vector<pii> graph[100100];
vector<edge> edges;
ull  bcj[100100];
const ull INF = 0xffffffffffffffff;
ull  find(ull  x)
{
	if(bcj[x] == INF) return x;
	ull  tmp = find(bcj[x]);
	bcj[x] = tmp;
	return tmp;
}
bool trymerge(ull  x, ull  y)
{
	ull  p = find(x), q = find(y);
	if(p != q) 
	{
		bcj[q] = p;
		return 1;
	}
	return 0;
}
bool cmp(edge x, edge y)
{
	return x.w < y.w;
}
void gen () {
	scanf ("%llu%llu%llu%llu", &n, &m, &k1 , &k2);
//	for(ull i=0; i<n; i++) graph[i].clear();
	edges.clear();
	for ( ull i = 1; i <= m; ++i) 
	{
		u = xorShift128Plus () % n + 1;
		v = xorShift128Plus () % n + 1;
		w = xorShift128Plus () ;
//		cin >> u >> v >> w;
//		graph[u].push_back({v, w});
//		graph[v].push_back({u, w});
		edges.push_back(edge(w, u, v));
	}
}

int main()
{
	ull  z;
	cin >> z;
	while(z--)
	{
		gen();
		memset(bcj, 0xff, sizeof(ull ) * (n+5));
		sort(edges.begin(),edges.end(), cmp);
		ull comp = n;
		ull ans = 0;
		for(ull i=0; i<m; i++)
		{
			edge &cur = edges[i];
			if(trymerge(cur.x, cur.y))
			{
				ans = (ans + cur.w %M) % M;
				comp--;
			}
			if(comp == 1) break;
		}
		cout << ans << '\n';
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 14ms
memory: 6344kb

input:

1
2 100000 123456789 987654321

output:

575673759

result:

ok single line: '575673759'

Test #2:

score: -100
Wrong Answer
time: 1211ms
memory: 6400kb

input:

100
17085 100000 676466090490 878574984049
24353 100000 685976930882 229685257786
4 100000 471961964055 157860429766
15406 100000 410376133349 828755231175
1 100000 809050431491 785471826497
1796 100000 218311747353 410830725634
93449 100000 761721499751 355474414706
3214 100000 277812617111 2429646...

output:

436638303
216567542
405150678
355979925
0
50713419
918381795
512195596
338362921
521086329
139607202
289558312
831627251
345103943
788519192
306890280
168133083
308823048
813378518
25758919
733644946
851485656
196406140
128088006
80292565
315609167
632805182
745061180
939817511
995073785
854970966
9...

result:

wrong answer 2nd lines differ - expected: '0', found: '216567542'