To commemorate the return (not yet), the traditional brush wave
Slf
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <
Queue> using namespace std;
const int MAXN = 100000 + 5; struct Edge {int f,t,v;}
L[MAXN << 1];
int FIRST[MAXN],NEXT[MAXN << 1],tot;
void Init () {memset (first,0xfff,sizeof (first));
tot = 0;
Return
} void Build (int f,int T,int v) {L[++tot] = (edge) {f,t,v};
Next[tot] = first[f];
FIRST[F] = tot;
Return
} deque <int> Q;
int DIS[MAXN],USE[MAXN];
void spfa_slf (int s) {memset (dis,0x3f,sizeof (dis));
memset (use,0,sizeof (use));
while (!q.empty ()) Q.pop_front ();
Q.push_back (s);
Use[s] = true;
Dis[s] = 0;
Q.push_back (0);
while (!q.empty ()) {int u = q.front ();
Q.pop_front ();
Use[u] = false;
for (int i = first[u];i! = -1;i = Next[i]) {int v = l[i].t; if (Dis[v] > Dis[u] + l[i].v) {Dis[v] = dis[u] + l[i].v; DIS[V] < Dis[q.front ()]?
Q.push_front (v): Q.push_back (v);
}}} return;
} int f,t,v;
int n,m,s,e;
int main () {init ();
scanf ("%d%d%d%d", &n,&m,&s,&e);
for (int i = 1;i <= m;i + +) {scanf ("%d%d%d", &f,&t,&v);
Build (F,T,V);
Build (T,F,V);
} SPFA_SLF (s);
printf ("%d\n", Dis[e]);
return 0; }