
cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 103, M = 116300, INF = 0x3f3f3f3f;
typedef long long int LL;
typedef unsigned long long int ULL;
const int mod = 1000000007;
#define x first
#define y second
typedef pair<int, LL> PIL;
typedef pair<int, int> PII;
int n, m;
int g[N][N];
int floyd()
{
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (g[i][j] > g[i][k] + g[k][j])
{
g[i][j] = g[i][k] + g[k][j];//利用floyd算法更新两个点之间的路径
}
}
}
}
int res = 0;
for (int i = 1; i <= n; i++)
{
if (g[1][i] == INF)
return -1;
res = max(res, g[1][i]);
}//如果有个点到1(指挥部)的距离为INF,则说明有个地方信息传不到,输出-1,否则输出最晚传达到的阵营所需的时间。
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
memset(g, 0x3f, sizeof g);
for (int i = 0; i < m; i++)
{
int a, b, c;
cin >> a >> b >> c;
g[a][b] = g[b][a] = min(g[a][b], c);
}
int res = floyd();
cout << res << endl;
return 0;
}