QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125533#415. 最小生成树yingmanji#Compile Error//C++14557b2023-07-16 20:10:372023-07-16 20:10:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 20:10:38]
  • 评测
  • [2023-07-16 20:10:37]
  • 提交

answer

#include <iostream>

using namespace std;
const int N=2e5+5;
int n,m,f[N],ans;
struct E{int u,v,w;}e[N];
inline int cmp(E x,E y){return x.w<y.w;}
inline int find(int x){return f[x]==x?f[x]:f[x]=find(f[x]);}
inline void merge(int a,int b){f[find(a)]=find(b);}
int main(int argc, char *argv[]) {
	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;
	sort(e+1,e+m+1,cmp);
	for(int i=1;i<=m;i++){
		if(find(e[i].u)!=find(e[i].v)){
			merge(e[i].u,e[i].v);
			ans+=e[i].w;
		}
	}
	cout<<ans<<endl;
}

詳細信息

answer.code: In function ‘int main(int, char**)’:
answer.code:14:9: error: ‘sort’ was not declared in this scope; did you mean ‘short’?
   14 |         sort(e+1,e+m+1,cmp);
      |         ^~~~
      |         short