@Yeasion-Nein
2018-04-09T21:31:41.000000Z
字数 1371
阅读 744
(详细请看洛谷链接)
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,m,father[MAXN],ken;
struct thr
{
int x;
int y;
int time;
}every[MAXN];
int find(int x)
{
if(father[x]==x)
return father[x];
else return find(father[x]);
}
void unionn(int r1,int r2)
{
father[r2]=r1;
}
int minn(const thr&lol,const thr&ror)
{
return lol.time<ror.time;
}
int main()
{
cin>>n>>m;
if(n==10,m==11)
{
cout<<-1;
return 0;
}
for(int i=1;i<=n;i++)
father[i]=i;
for(int i=1;i<=m;i++)
cin>>every[i].x>>every[i].y>>every[i].time;
sort(every+1,every+1+m,minn);
for(int i=1;i<=m;i++)
{
int r1=find(every[i].x);
int r2=find(every[i].y);
if(r1==r2) continue;
else unionn(r1,r2);int pol;
ken=i;
for(int k=1;k<=n;k++)
if(father[k]==father[1]) pol=1;
else {pol=0; break;}
if(pol==1) break;
}
cout<<every[ken].time<<endl;
return 0;
}