QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865118 | #8941. Even or Odd Spanning Tree | hehehy | WA | 0ms | 5732kb | C++14 | 760b | 2025-01-21 15:05:55 | 2025-01-21 15:05:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int t,n,m,f[200005];
int find(int x){
if(f[x]==x) return x;
return f[x]=find(f[x]);
}
struct node{
int u,v,z;
}st[200005];
bool cmp(node a,node b){
return a.z<b.z;
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
f[i]=i;
}
for(int i=1;i<=m;i++){
cin>>st[i].u>>st[i].v>>st[i].z;
}
long long k1=-1,sum=0,num=0;
sort(st+1,st+m+1,cmp);
for(int i=1;i<=m;i++){
int u=st[i].u,v=st[i].v,w=st[i].z;
if(find(u)!=find(v)){
f[find(u)]=find(v);
sum+=w;
if(++num>=n-1){
k1=sum;
break;
}
}
}
sum=num=0;
for(int i=1;i<=n;i++){
f[i]=i;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5732kb
input:
3 2 1 1 2 5 3 1 1 3 1 4 4 1 2 1 1 3 1 1 4 1 2 4 2
output:
result:
wrong answer Answer contains longer sequence [length = 6], but output contains 0 elements