using namespace std;
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
vector<int> g[30100], co[30100];
int N, M, D[30100], X, Y, q[30100], u[30100], deg[30100];
char * p;
int baga()
{
int ret = 0;
while( *p != '\n' && *p != '\0' && isdigit(*p) )
ret *= 10,
ret += *p - '0',
p++;
return ret;
}
int main()
{
freopen("sate.in", "r", stdin);
freopen("sate.out", "w", stdout);
char buf[100];
scanf("%d %d %d %d \n", &N, &M, &X, &Y);
int x, y, c, l, r, el;
for( int i = 0; i < M; i++ )
{
/*
scanf("%d %d %d", &x, &y, &c);
*/
gets( buf );
p = buf;
x = baga(), p++, y = baga(), p++, c = baga();
deg[x]++, deg[y]++;
/*
g[x].push_back(y), g[y].push_back(x);
co[x].push_back(c), co[y].push_back(c);
*/
}
fseek(stdin, 0, SEEK_SET);
scanf("%d %d %d %d \n", &N, &M, &X, &Y);
for( int i = 1; i <= N; i++ )
g[i].resize( deg[i] ),
co[i].resize( deg[i] );
for( int i = 0; i < M; i++ )
{
gets( buf );
p = buf;
x = baga(), p++, y = baga(), p++, c = baga();
g[x][ --deg[x] ] = y, g[y][ --deg[y] ] = x;
co[x][ deg[x] ] = c, co[ y ][ deg[y] ] = c;
}
for( int i = 1; i <= N; i++ )
D[i] = (1<<28);
D[X] = 0;
for( q[ l = r = 0 ] = X; l <= r; l++ )
{
el = q[l];
u[el] = 1;
for( int j = 0; j < (int)g[el].size(); ++j )
{
y = g[el][j], c = co[el][j];
if( u[y] )
continue;
u[y] = 1;
q[++r] = y;
if( X < el )
{
if( y < X )
D[y] = c - D[el];
else if( y < el )
D[y] = D[el] - c;
else
D[y] = D[el] + c;
}
else
{
if( y < el )
D[y] = D[el] + c;
else if( y < X )
D[y] = D[el] - c;
else
D[y] = c - D[el];
}
}
}
printf("%d\n", D[Y] );
return 0;
}