最小生成树水题。。感觉二分都能写。。
当做休息了,,,
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-48,ch=getchar();
return x*w;
}
const int maxn = 1e6+5;
struct edge
{
int x,y,t;
}a[maxn];
int f[maxn],n,m;
int cmp(edge a,edge b){return a.t<b.t;}
int find(int x){return f[x]==x?x:(f[x]=find(f[x]));}
int main()
{
n=read(), m=read();
for(int i=1;i<=m;i++)
a[i].x=read(),a[i].y=read(),a[i].t=read();
sort(a+1,a+m+1,cmp);
for(int i=1;i<=n;i++)f[i]=i;
int ct = 0;
for(int i=1;i<=m;i++)
{
int fx=find(a[i].x),fy=find(a[i].y);
if(fx!=fy) f[fx]=fy,ct++;
if(ct == n-1){cout<<a[i].t; return 0;}
}
cout<<-1<<endl;
return 0;
}