[codec]
#include<iostream>
#include<algorithm>
#define MAX(X,Y) X>Y?X:Y
#define MIN(X,Y) X<Y?X:Y
using namespace std;
struct e
{
int begin;
int end;
int weight;
}edges[11111];
int parents[2222]={0};
int graph[2222][2222];
int maxe=0;
bool cmp(e x,e y)
{
return x.weight<y.weight;
}
int find(int x)
{
if(x!=parents[x])
parents[x]=find(parents[x]);
return parents[x];
}
int main()
{
int n,m;
int i,j,k=1;
int x,y;
int a,b,w;
cin>>n>>m;
for(i=1;i<=n;i++)
parents[i]=i;
for(i=1;i<2222;i++)
for(j=1;j<2222;j++)
graph[i][j]=65536;
for(i=1;i<=m;i++)
{
cin>>a>>b>>w;
graph[a][b]=MIN(graph[a][b],w);
graph[b][a]=graph[a][b];
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(graph[i][j]<65536 && i!=j)
{
edges[k].begin=i;
edges[k].end=j;
edges[k].weight=graph[i][j];
k++;
};
sort(edges+1,edges+n+1,cmp);
for(i=1;i<=m;i++)
{
x=find(edges[i].begin);
y=find(edges[i].end);
if(x!=y)
{
parents[x]=y;
maxe=MAX(edges[i].weight,maxe);
}
}
cout<<maxe<<endl;
return 0;
}
[/codec]