#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define NMax 305
#define MMax 1505
int N, S[NMax], X[NMax * NMax], Y[NMax * NMax], cst[NMax * NMax], OPT[NMax][NMax], sA, sB;
vector< pair<int, int> > G[NMax];
int main(void)
{
int M, u, v, D, i, j;
vector< pair<int, int> >::iterator it;
freopen("sate.in", "r", stdin);
freopen("sate.out", "w", stdout);
memset(OPT, 0, sizeof(OPT));
scanf("%d %d %d %d", &N, &M, &sA, &sB);
for (i = 1; i <= M; i++)
{
scanf("%d %d %d", &u, &v, &D);
X[i] = u; Y[i] = v; cst[i] = D;
}
for (i = 1; i <= M; i++)
for (j = 1; j <= M; j++)
if (i != j)
{
if (X[i] == X[j])
{
if (Y[i] < Y[j] && !OPT[Y[i]][Y[j]])
M++, X[M] = Y[i], Y[M] = Y[j], cst[M] = cst[j] - cst[i],
OPT[Y[i]][Y[j]] = cst[M];
else if (Y[j] < Y[i] && !OPT[Y[j]][Y[i]])
M++, X[M] = Y[j], Y[M] = Y[i], cst[M] = cst[i] - cst[j],
OPT[Y[j]][Y[i]] = cst[M];
}
else if (Y[i] == Y[j])
{
if (X[i] < X[j] && !OPT[X[i]][X[j]])
M++, X[M] = X[i], Y[M] = X[j], cst[M] = cst[i] - cst[j],
OPT[X[i]][X[j]] = cst[M];
else if (X[j] < X[i] && !OPT[X[j]][X[i]])
M++, X[M] = X[j], Y[M] = X[i], cst[M] = cst[j] - cst[i],
OPT[X[j]][X[i]] = cst[M];
}
}
for (i = 1; i <= M; i++)
G[X[i]].pb( mp(Y[i], cst[i]) );
for (S[1] = 0, i = 2; i <= N; i++) S[i] = -1;
for (i = 1; i <= N; i++)
{
if (S[i] == -1) continue;
for (it = G[i].begin(); it != G[i].end(); it++)
S[it->f] = S[i] + it->s;
}
printf("%d\n", S[sB]-S[sA]);
return 0;
}