#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> const int INF = 0x3f3f3f3f; using namespace std; int n; bool vis[1005]; bool flag; int dis[1005][1005]; int d[1005]; int mak[1005]; void init(){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ dis[i][j] = INF; } dis[i][i] = 0; mak[i] = 1; } } int dijkstra(){ for(int i = 1; i <= n; i++){ vis[i] = 0; d[i] = dis[1][i]; } vis[1] = 1; for(int i = 1; i <= n; i++){ int k = -1; int minn = INF; for(int j = 1; j <= n; j++){ if(!vis[j] && minn > d[j]){ k = j; minn = d[j]; } } if(k == -1) break; vis[k] = 1; for(int j = 1; j <= n; j++){ if(!vis[j] && d[j] > d[k] + dis[k][j]){ d[j] = d[k] + dis[k][j]; if(!flag)mak[j] = k; } } } return d[n]; } int main(){ int m; while(~scanf("%d%d", &n, &m)){ init(); for(int i = 0; i < m; i++){ int x, y, w; scanf("%d%d%d", &x, &y, &w); dis[x][y] = dis[y][x] = w; } flag = 0; int ans = dijkstra(); flag = 1; for(int i = n; i != 1; i = mak[i]){//最短路径上的点; int j = mak[i]; int tep = dis[i][j];//最短路径上的边; dis[i][j] = dis[j][i] = INF;//分别断开最短路径上的边; int temp = dijkstra(); ans = max(ans, temp); dis[i][j] = dis[j][i] = tep;//恢复最短路径上的边; } printf("%d ",ans); } return 0; }