#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N=2505,M=6205;
int n,m,s,t;
int h[M],ne[M],e[M],val[M],idx;
int dis[N];
bool st[N];
void add(int a,int b,int w){
val[idx]=w,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
void dijkstra(){
memset(dis,0x3f,sizeof dis);
dis[s]=0;
priority_queue<pii,vector<pii>,greater<pii> >q;
q.push({0,s});
while(!q.empty()){
auto t=q.top();
q.pop();
int ver=t.second;
if(st[ver]) continue;
st[ver]=true;
for(int i=h[ver];i!=-1;i=ne[i]){
int j=e[i];
if(dis[j]>dis[ver]+val[i]){
dis[j]=dis[ver]+val[i];
q.push({dis[j],j});
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>m>>s>>t;
memset(h,-1,sizeof h);
for(int i=1;i<=m;i++){
int a,b,w;
cin>>a>>b>>w;
add(a,b,w);
add(b,a,w);
}
dijkstra();
cout<<dis[t]<<endl;
return 0;
}