#include<queue>
#include<cstdio>
#include<iostream>
using namespace std;
struct node {
int to,dis,next;
};
struct node edge[12801];
int num_head,num_edge,num,start,end,head[2501],dis[2501];
char word;
void spfa(int all_from)
{
queue<int>que;
bool if_in_spfa[2501];
for(int i=1 ; i<=num_head ; i++) dis[i]=99990000,if_in_spfa[i]=false;
dis[all_from]=0;
if_in_spfa[all_from]=true;
que.push(all_from);
int cur_1;
while(!que.empty())
{
cur_1=que.front();
que.pop();
for(int i=head[cur_1] ; i ; i=edge[i].next)
{
if(dis[cur_1]+edge[i].dis<dis[edge[i].to])
{
dis[edge[i].to]=dis[cur_1]+edge[i].dis;
if(!if_in_spfa[edge[i].to])
{
if_in_spfa[edge[i].to]=true;
que.push(edge[i].to);
}
}
}
if_in_spfa[cur_1]=false;
}
}
inline void read_int(int &now_001)
{
now_001=0;word=getchar();
while(word<‘0‘||word>‘9‘) word=getchar();
while(word<=‘9‘&&word>=‘0‘)
{
now_001=now_001*10+(int)(word-‘0‘);
word=getchar();
}
}
inline void edge_add(int from,int to,int dis)
{
num++;
edge[num].to=to;
edge[num].dis=dis;
edge[num].next=head[from];
head[from]=num;
}
int main()
{
ios::sync_with_stdio(false);
read_int(num_head),read_int(num_edge),read_int(start),read_int(end);
int from,to,dis1;
for(int i=1 ; i<=num_edge ; i++)
{
read_int(from),read_int(to),read_int(dis1);
edge_add(from,to,dis1);
edge_add(to,from,dis1);
}
spfa(start);
printf("%d\n",dis[end]);
return 0;
}