#include <iostream>
#include <fstream>
#include <map>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <set>
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");
///#define f cin
///#define g cout
#define NMAX 110000
int n, m, x, y;
vector<pair<int,int>> adj[NMAX];
int dist[NMAX];
int viz[NMAX];
queue<int> q;
void bfs()
{
while (!q.empty())
{
int curent = q.front();
q.pop();
viz[curent] = 1;
for (auto vecin : adj[curent])
{
if (!viz[vecin.first])
{
viz[vecin.first] = 1;
dist[vecin.first] = dist[curent] + vecin.second;
q.push(vecin.first);
}
}
}
}
int main()
{
f >> n >> m >> x >> y;
for (int i = 1; i <= m; i++)
{
int a, b, w;
f >> a >> b >> w;
adj[a].push_back({ b,w });
adj[b].push_back({ a,-w });
}
q.push(1);
if (adj[1].size() == 0)
return 0;
q.push(x);
bfs();
g << dist[y];
return 0;
}