QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865118#8941. Even or Odd Spanning TreehehehyWA 0ms5732kbC++14760b2025-01-21 15:05:552025-01-21 15:05:56

Judging History

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

  • [2025-01-21 15:05:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5732kb
  • [2025-01-21 15:05:55]
  • 提交

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