#define INF 0x3f3f3f3f int G[N][N]; //邻接矩阵 bool visit[N]; //访问数组 intmain(){ int n, m; scanf("%d%d", &n, &m); //n个点m条边 //邻接矩阵初始化 for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) G[i][j] = INF; //建图 for (int i = 1; i <= m; i++) { int x, y, w; scanf("%d%d%d", &x, &y, &w); if (w < G[x][y]) { G[x][y] = w; G[y][x] = w; } } for (int k = 1; k <= n; k++) //枚举中间点 for (int i = 1; i <= n; i++) //枚举起点 for (int j = 1; j <= n; j++) //枚举终点 G[i][j] = min(G[i][j], G[i][k] + G[k][j]); printf("%d\n", G[1][n]); //从起点1到起点n的最短路长度 return0; }