#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,k,ans,x,y;
vector<pair<int,int>>g[30005];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
freopen("sate.in", "r", stdin);
freopen("sate.out", "w", stdout);
cin>>n>>m>>x>>y;
while (m--)
{
int d;
cin>>i>>j>>d;
g[i].push_back({d,j});
g[j].push_back({d,i});
}
vector<int>dist(n+1,INT_MAX);
dist[x]=0;
pq.push({0,x});
while (!pq.empty())
{
int d=pq.top().first;
int u=pq.top().second;
pq.pop();
if (d>dist[u])
{
continue;
}
for (auto v : g[u])
{
if (dist[u]+v.first<dist[v.second])
{
dist[v.second]=dist[u]+v.first;
pq.push({dist[v.second],v.second});
}
}
}
cout<<dist[y];
}