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;
}
就是后面的合并出了问题