为啥CE?
  • 板块灌水区
  • 楼主zhz_2013
  • 当前回复9
  • 已保存回复10
  • 发布时间2024/8/14 19:45
  • 上次更新2024/8/14 21:47:37
查看原帖
为啥CE?
980236
zhz_2013楼主2024/8/14 19:45

rt,说是‘int[int]’用作数组下标类型无效,但我是int类型,不是数组地址啊???
code:

#include<bits/stdc++.h>
using namespace std;
int t[20005],y[20005],n,m;
struct node{
	int st,e,v;
}g[100005];
int find(int x){
	if(x==t[x])return x;
	return t[x]=find(t[x]);
}
bool cmp(const node lhs,const node rhs){
	return lhs.v>rhs.v;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)t[i]=i;
	for(int i=1;i<=m;i++)cin>>g[i].st>>g[i].e>>g[i].v;
	sort(g+1,g+m+1,cmp);
	for(int i=1;i<=m;i++){
		int x=find(g[i].st),y=find(g[i].e);
		if(x==y){
			cout<<g[i].v<<endl;
			return 0;
		}
		int f1=g[i].st,f2=g[i].e;
		if(!y[f1]){
			y[f1]=f2;
		}else{
			t[find(y[f1])]=t[f2];
		}
		if(y[g[i].e] == 0){
			y[g[i].e]=g[i].st;
		}else{
			t[find(y[g[i].e])]=t[g[i].st];
		}
	}
	puts("0");
	return 0;
}

就是后面的合并出了问题

2024/8/14 19:45
加载中...