#include<cstdio>
#include<cstring>
#include<algorithm>
#define MIN(x,y) ((x)>(y)?(y):(x))
using namespace std;
int pre[1000];
struct node
{
int u,v,w;
}e[1600];
bool cmp(const node &a,const node &b)
{
return a.w<b.w;
}
int find(int x)
{
return x==pre[x]?x:pre[x]=find(pre[x]);
}
void unite(int x,int y)
{
int t1=find(x);
int t2=find(y);
pre[t1]=t2;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
sort(e,e+m,cmp);
int res=10000000;
for(int i=0;i<m;i++)
{
for(int j=0;j<=n;j++)
pre[j]=j;
for(int j=i;j<m;j++)
{
unite(e[j].u,e[j].v);
if(find(1)==find(n))
{
res=MIN(res,e[j].w-e[i].w);
break;
}
}
}
printf("%d\n",res);
}
求点1 到点n 所有路径中 最大值与最小值之差 最小的那个
最新推荐文章于 2020-07-15 21:48:13 发布