求调样例不对结果ac
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define l(rt) rt<<1
#define r(rt) rt<<1|1
const int N=3e5+6,yyx=4e9+7;
int n,k,pre[N],st[N];
vector<PII> to[N];
bool check(int x){
//memset(st,0,sizeof st);
set<int> s;
for(int i=1;i<=n;++i){
for(auto c:to[i]){
int j=c.first,w=c.second;
if(x>=w) s.insert(j);
}
}
int ans=s.size();
//cout<<ans<<" "<<x<<endl;
if(ans>=n) return 1;
return 0;
}
void solve(){
cin>>n>>k;
for(int i=1;i<=k;++i){
int x,y,t;cin>>x>>y>>t;
to[x].push_back({y,t});
to[y].push_back({x,t});
}
int l=0,r=1e5+1;
while(l+1<r){
int m=l+r>>1;
if(check(m)) r=m;
else l=m;
}
if(!l||r==1e5+1) cout<<-1<<endl;
else cout<<r<<endl;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int _=1;
//cin>>_;
while(_--)
solve();
return 0;
}