为什么总是编译失败??
查看原帖
为什么总是编译失败??
373819
lizichang楼主2021/9/3 21:48
#include<bits/stdc++.h>
using namespace std;
int n,m,fa[1005];
struct node
{
	int x,y,t;
}edge[100005];
int cmp(node x,node y)
{
	return x.t<y.t;
}
int find(int x)
{
	if(fa[x]==x)	return fa[x];
	else return fa[x]=find(fa[x]);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)	fa[i]=i;
	for(int i=1;i<=m;i++)	cin>>edge[i].x>>edge[i].y>>edge[i].t;
	sort(edge+1,edge+m+1,cmp);
	int cnt=0,ans=0;
	for(int i=1;i<=m;i++)
	{
		int ex=find(edge[i].x),ey=find(edge[i].y);
		if(ex==ey)	continue;
		fa[ex]=ey;
		ans=max(ans,edge[i].t);
		if(cnt++==n-1)	break;
	}
	if(cnt<n-1)	cout<<-1;
	cout<<ans;
	return 0;
}

在DEV上还没有问题呀? 要提交到什么语言上?

2021/9/3 21:48
加载中...