QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625408 | #7003. Rikka with Minimum Spanning Trees | ucup-team5071# | AC ✓ | 780ms | 7336kb | C++20 | 1.7kb | 2024-10-09 19:07:13 | 2024-10-09 19:07:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct edge{
int u,v;
unsigned long long w;
bool operator <(const edge& other) const {
return w < other.w;
}
} e[100001];
const unsigned long long P = 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;
}
int n, m, u [100001] , v [100001];
unsigned long long w [100001];
void gen () {
scanf ("%d%d%llu%llu", &n, &m, &k1 , &k2);
for ( int i = 1; i <= m; ++i) {
u[i] = xorShift128Plus () % n + 1;
v[i] = xorShift128Plus () % n + 1;
w[i] = xorShift128Plus () ;
}
}
int fa[100001];
int get_fa(int x){
if (fa[x] == x) return x;
return fa[x] = get_fa(fa[x]);
}
bool merge(int x,int y){
int fx = get_fa(x);
int fy = get_fa(y);
if (fx == fy) return false;
fa[fx] = fy;
return true;
}
void solve(){
gen();
for (int i = 1; i <= n; ++i){
fa[i] = i;
}
for (int i = 1; i <= m; ++i){
e[i].u = u[i];
e[i].v = v[i];
e[i].w = w[i];
}
sort(e+1,e+m+1);
unsigned long long ans = 0;
int cnt=0;
for (int i = 1; i <= m; ++i){
// if (i <= 10) {
// cout << e[i].u << " " << e[i].v << " " << e[i].w << "\n";
// }
if (merge(e[i].u,e[i].v)){
cnt++;
ans += e[i].w%P;
ans %= P;
}
}
if(cnt==n-1)printf("%llu\n",ans);
else printf("0\n");
}
int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int T;
// cin >> T;
scanf("%d",&T);
while(T--){
solve();
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 9ms
memory: 6992kb
input:
1 2 100000 123456789 987654321
output:
575673759
result:
ok single line: '575673759'
Test #2:
score: 0
Accepted
time: 780ms
memory: 7336kb
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