样例没过,贪心蒜法无并查集显然是错的,样例没过,AC了……
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m;
int B[N];
int ans;
class Node{
public:
int x;
int y;
int t;
bool operator<(Node& b){
return t<b.t;
}
}a[N];
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a[i].x>>a[i].y>>a[i].t;
}
sort(a+1,a+m+1);
for(int i=1;i<=m;i++){
if(B[a[i].x]==0) ans++,B[a[i].x]=1;
if(B[a[i].y]==0) ans++,B[a[i].y]=1;
if(ans>=n) {
cout<<a[i].t;
return 0;
}
}
cout<<"-1";
return 0;
}