1128. 信使
作者:
闪回
,
2024-04-01 16:07:45
,
所有人可见
,
阅读 2
floyd到其它所有点的最小值,求一个最大值
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int d[N][N];
int n,m;
int main()
{
cin>>n>>m;
memset(d,0x3f,sizeof d);
for(int i = 1;i<=n;i++)d[i][i] = 0;
while(m--)
{
int a,b,c;
cin>>a>>b>>c;
d[a][b] = d[b][a] = min(d[a][b],c);
}
for(int k = 1;k<=n;k++)
for(int i = 1;i<=n;i++)
for(int j = 1;j<=n;j++)
d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
int res = 0;
for(int i = 1;i<=n;i++)
{
if(d[1][i] == 0x3f3f3f3f)
{
res = -1;
break;
}
else
{
res = max(res,d[1][i]);
}
}
cout<<res<<endl;
}