不同版本运行和本地运行结果不同?
  • 板块学术版
  • 楼主Zcras
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/10/8 17:13
  • 上次更新2024/10/8 18:20:05
查看原帖
不同版本运行和本地运行结果不同?
573977
Zcras楼主2024/10/8 17:13

rt,题目,本地下载数据ac

评测记录 中代码没有变,只是改变了编译的版本,得分不同,是哪里的问题?

#include <bits/stdc++.h>
using namespace std;
const int N=5e3+10,M=2e5+10;
struct edge{
	int u,v,w;
}e[M];
int n,m,ans,f[N],tot;
bool cmp(edge a,edge b){return a.w<b.w;}
int finds(int x){return f[x]==x?x:f[x]=finds(f[x]);}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		f[i]=i;
	for(int i=1;i<=m;i++){
		cin>>e[i].u>>e[i].v>>e[i].w;
		f[finds(e[i].u)]=finds(e[i].v);
	}
	int tot=0;
	bool pd[n];
	for(int i=1;i<=n;i++){
	    if(!pd[finds(i)]){
	        pd[finds(i)]=1;
	        tot++;
	    }
	}
	if(tot!=1){
	    cout<<"orz"<<endl;
	    return 0;
	}
	for(int i=1;i<=n;i++)
		f[i]=i;
	sort(e+1,e+m+1,cmp);
	for(int i=1;i<=m;i++){
		if(finds(e[i].u)==finds(e[i].v))continue;
		f[finds(e[i].u)]=finds(e[i].v),ans+=e[i].w;
	    tot++;
	}
	cout<<ans<<endl;
	return 0;
}
2024/10/8 17:13
加载中...