QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155341#7003. Rikka with Minimum Spanning TreesPetroTarnavskyi#AC ✓895ms6596kbC++171.8kb2023-09-01 15:59:452023-09-01 15:59:45

Judging History

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

  • [2023-09-01 15:59:45]
  • 评测
  • 测评结果:AC
  • 用时:895ms
  • 内存:6596kb
  • [2023-09-01 15:59:45]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

typedef unsigned long long ULL;

const int mod = 1'000'000'007;
const int MAX = 100001;

void updAdd(int& x, int val)
{
	x += val;
	if (x >= mod)
	{
		x -= mod;
	}
}

struct DSU
{
	int n;
	VI p, sz;
	void init(int _n)
	{
		n = _n;
		p.resize(n);
		iota(ALL(p), 0);
		sz.assign(n, 1);
	}
	int find(int v)
	{
		if (p[v] == v)
			return v;
		return p[v] = find(p[v]);
	}
	bool unite(int u, int v)
	{
		u = find(u);
		v = find(v);
		if (u == v)
			return false;
		if (sz[u] > sz[v])
			swap(u, v);
		p[u] = v;
		sz[v] += sz[u];
		return true;
	}
} dsu;

ULL k1, k2;

ULL xorShift128Plus()
{
	ULL k3 = k1, k4 = k2;
	k1 = k4;
	k3 ^= k3 << 23;
	k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
	return k2 + k4;
}

int n, m, u[MAX], v[MAX];
ULL w[MAX];
int idxes[MAX];

void gen()
{
	cin >> n >> m >> k1 >> k2;
	FOR(i, 0, m)
	{
		u[i] = xorShift128Plus() % n;
		v[i] = xorShift128Plus() % n;
		w[i] = xorShift128Plus();
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		gen();
		iota(idxes, idxes + m, 0);
		sort(idxes, idxes + m, [](int i, int j) {return w[i] < w[j];});
		dsu.init(n);
		int ans = 0;
		FOR(i, 0, m)
		{
			int j = idxes[i];
			if (dsu.unite(u[j], v[j]))
				updAdd(ans, w[j] % mod);
		}
		if (dsu.sz[dsu.find(0)] != n)
			ans = 0;
		cout << ans << "\n";
	}
	
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 5616kb

input:

1
2 100000 123456789 987654321

output:

575673759

result:

ok single line: '575673759'

Test #2:

score: 0
Accepted
time: 895ms
memory: 6596kb

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
0
405150678
355979925
0
50713419
0
512195596
338362921
0
0
289558312
831627251
345103943
788519192
306890280
168133083
308823048
813378518
25758919
733644946
851485656
0
0
0
315609167
632805182
745061180
0
995073785
854970966
0
0
0
423134815
0
867689881
500810440
0
0
0
945701987
0
0
0
1959...

result:

ok 100 lines