#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
#define INF 9999999
#define MAXN 10240
struct NODE{
int num;
int nextt[MAXN],e[MAXN];
}p[MAXN];
int n,en,t;
bool vis[MAXN]={0};
int d[MAXN];
queue <int> q;
int spfa(int root){
for(int i=1;i<=n;i++) d[i]=(i==root)?0:INF;
q.push(root);
vis[root]=1;
while(!q.empty()){
t=q.front();
q.pop();
vis[t]=0;
for(int i=1;i<=p[t].num;i++){
if(d[p[t].nextt[i]]>d[t]+p[t].e[i]){
d[p[t].nextt[i]]=d[t]+p[t].e[i];
if(!vis[p[t].nextt[i]]){
vis[p[t].nextt[i]]=1;
q.push(p[t].nextt[i]);
}
}
}
}
return d[en];
}
int main()
{
int m,beg,l,r,w;
scanf("%d %d %d %d",&n,&m,&beg,&en);
for(int i=1;i<=m;i++){
scanf("%d %d %d",&l,&r,&w);
p[l].num++;
p[l].nextt[p[l].num]=r;
p[l].e[p[l].num]=w;
p[r].num++;
p[r].nextt[p[r].num]=l;
p[r].e[p[r].num]=w;
}
printf("%d\n",spfa(beg));
return 0;
}