#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,k,ans,x,y,d;
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("file.in", "r", stdin);
freopen("file.out", "w", stdout);
cin>>n>>m>>x>>y;
while (m--)
{
cin>>i>>j>>d;
g[i].push_back({d,j});
g[j].push_back({d,i});
}
vector<int>prev(n+1,-1);
pq.push({0,x});
while (!pq.empty())
{
int dist=pq.top().first;
int u=pq.top().second;
pq.pop();
for (auto v : g[u])
{
if (prev[v.second]==-1)
{
pq.push({dist+v.first,v.second});
}
}
}
}