/* The Shortest Path + the minimum spanning tree. A graph is given, starting point, and ending point. Find the path from the start point to the end point (the longest section of this path must be the shortest !) Enumerate the "Longest path", which can be divided into two parts or calculated directly. */# Include <stdio. h> # include <string. h> # include <stdlib. h >#include <algorithm> # include <queue> using namespace std; const int maxn = 2005; const int maxm = 50005; const int inf = 99999999; int mat [maxn] [maxn]; int fa [maxn]; bool vis [maxn]; int dis [maxn]; struct Node {int x, y, val ;} edge [maxm <1]; int cmp (Node a, Node B) {return. val <B. val;} void init (int n) {for (int I = 1; I <= n; I ++) {fa [I] = I; for (int J = 1; j <= n; j ++) {mat [I] [j] = inf ;}} int find (int x) {if (x = fa [x]) return x; return fa [x] = find (fa [x]);} int Kruskal (int n, int m, int A, int B) {sort (edge, edge + m, cmp); int x, y; int MaxEdge = 0; for (int I = 0; I <m; I ++) {x = find (edge [I]. x); y = find (edge [I]. y); if (x! = Y) {if (x> y) fa [y] = x; else fa [x] = y; if (find (A) = find (B )) {MaxEdge = edge [I]. val; return MaxEdge;} MaxEdge = max (MaxEdge, edge [I]. val) ;}} return MaxEdge;} int Dij (int n, int MaxEdge, int A, int B) {for (int I = 1; I <= n; I ++) {vis [I] = false; dis [I] = inf;} dis [A] = 0; for (int I = 1; I <= n; I ++) {int M = inf; int id =-1; for (int j = 1; j <= n; j ++) {if (! Vis [j] & M> dis [j]) {M = dis [j]; id = j ;}} if (id =-1) break; vis [id] = true; for (int j = 1; j <= n; j ++) {if (! Vis [j] & dis [j]> dis [id] + mat [id] [j] & mat [id] [j] <= MaxEdge) {dis [j] = dis [id] + mat [id] [j] ;}} return dis [B];} int main () {// freopen ("in.txt", "r", stdin); int n, m, A, B; while (scanf ("% d ", & n, & m, & A, & B )! = EOF) {init (n); for (int I = 0; I <m; I ++) {scanf ("% d ", & edge [I]. x, & edge [I]. y, & edge [I]. val); if (mat [edge [I]. x] [edge [I]. y]> edge [I]. val) {mat [edge [I]. x] [edge [I]. y] = mat [edge [I]. y] [edge [I]. x] = edge [I]. val ;}} int MaxEdge = 0; MaxEdge = Kruskal (n, m, A, B); // printf ("MaxEdge = % d \ n", MaxEdge ); int Sum = Dij (n, MaxEdge, A, B); printf ("% d \ n", Sum );}}