QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656385 | #7003. Rikka with Minimum Spanning Trees | nekoyellow | WA | 1699ms | 12368kb | C++20 | 2.0kb | 2024-10-19 12:43:37 | 2024-10-19 12:43:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
const ull P = 1e9 + 7;
ull k1, k2;
ull rng() {
ull k3 = k1, k4 = k2;
k1 = k4;
k3 ^= k3 << 23;
k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
return k2 + k4;
}
struct Edge {
int u, v;
ull w;
};
bool operator<(const Edge &x, const Edge &y) {
return x.w < y.w;
}
void solve() {
int n, m;
cin >> n >> m >> k1 >> k2;
vector<Edge> a(m);
vector<int> p(n), sz(n, 1);
iota(p.begin(), p.end(), 0);
int nset = n;
auto find = [&](auto &&self, int u) {
if (u == p[u]) return u;
return p[u] = self(self, p[u]);
};
auto merge = [&](int u, int v) {
int ru = find(find, u), rv = find(find, v);
if (ru == rv) return false;
if (sz[ru] > sz[rv]) swap(ru, rv);
p[ru] = rv;
sz[rv] += sz[ru];
nset--;
return true;
};
for (int i = 0; i < m; i++) {
a[i].u = rng() % n;
a[i].v = rng() % n;
a[i].w = rng();
}
if (n == 2) {
ull mnw = -1;
int cnt = 0;
for (int i = 0; i < m; i++) {
if (a[i].u == a[i].v) continue;
mnw = min(mnw, a[i].w);
}
for (int i = 0; i < m; i++) {
if (a[i].u == a[i].v) continue;
if (a[i].w == mnw) cnt++;
}
cout << (ull)((__int128)cnt * mnw % P) << endl;
return;
}
multiset<Edge> pq;
for (int i = 0; i < n; i++) {
pq.emplace(a[i]);
}
ull ans = 0;
for (int i = 1; i < n; i++) {
auto [u, v, w] = *pq.begin();
cout << u << ' ' << v << ' ' << w << endl;
pq.extract(pq.begin());
if (!merge(u, v)) continue;
ans = ((__int128)ans + w) % P;
}
cout << (nset == 1 ? ans : 0) << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
for (; t; t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4836kb
input:
1 2 100000 123456789 987654321
output:
575673759
result:
ok single line: '575673759'
Test #2:
score: -100
Wrong Answer
time: 1699ms
memory: 12368kb
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:
6492 12736 1994219930030204 2428 9367 2107660301994219 1543 15058 5581013281396333 8193 5794 6613757193243627 5250 14044 6674211701226450 8534 9346 6805103902258620 2999 525 6943171102080968 5604 10787 8883190809157824 12884 1328 9539791981527731 9209 3846 9598203065777307 10808 11665 97497869244101...
result:
wrong answer 1st lines differ - expected: '436638303', found: '6492 12736 1994219930030204'