#include <bits/stdc++.h>
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
int n,m,x,y,a,b,d,distanta_fin;
vector<int>poz;
vector<vector<pair<int, int>>>graph;
void bfs(int node)
{
queue<int>q;
q.push(node);
while(!q.empty())
{
node=q.front();
q.pop();
for(auto it : graph[node]) {
int next=it.first;
int d=it.second;
if(poz[next] == -1)
{
if (next>node)
poz[next]=poz[node]+d;
if (next<node)
poz[next]=poz[node]-d;
q.push(next);
}
}
if (node == b)
break;
}
}
int main()
{
f>>n>>m>>a>>b;
poz.assign(n+1,-1);
graph.assign(n + 1, vector<pair<int, int>>());
for(int i=1; i<=m; i++)
{
f>>x>>y>>d;
graph[x].push_back({y,d});
graph[y].push_back({x,d});
}
poz[a] = 0;
bfs(a);
g<<poz[b];
return 0;
}