悬赏关注
#include <iostream>
#include <string.h>
#include <cmath>
#include <algorithm>
const int N = 2010;
const int M = 51010;
using namespace std;
int n,m,s,t;
int fa[N];
struct node{
int u,v,w;
}k[M];
bool compare(node x,node y)
{
if(x.w<y.w) return true;
else return false;
}
int find(int x)
{
if(x!=fa[x]) fa[x]=find(fa[x]);
return fa[x];
}
int main()
{
cin >> n >> m >> s >> t;
for (int i=1;i<=m;i++) fa[i]=i;
for (int i=1;i<=m;i++)
{
int u,v,w;
cin >> u >> v >> w;
k[i].u=u;k[i].v=v;k[i].w=w;
}
sort(k+1,k+m+1,compare);
for (int i=1;i<=m;i++)
{
int a=find(k[i].u),b=find(k[i].v);
if(a!=b)
{
fa[b]=a;
if(find(s)==find(t))
{
cout << k[i].w << endl;
return 0;
}
}
}
}