#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
using namespace std;
int viz[ 30000 ];
vector < int > mat[ 30000 ], l[ 30000 ];
long int n;
void bf (int start, int end )
{
long int x, suma = 0;
viz[ start ] = 1;
queue< int > c;
c.push( start );
while (!c.empty())
{
x = c.front();
c.pop();
for( int i = 0; i < mat[ x ].size(); i++)
if( !viz[ mat[ x ][ i ] ] )
{
viz[ mat[ x ][ i ] ]= 1;
c.push( mat[ x ][ i ] );
if( x > mat[ x ][ i ] )
suma -= l[ x ][ i ];
else
suma += l[ x ][ i ];
if( mat[ x ][ i ] == end )
goto loop1;
}
}
loop1:
ofstream g( "sate.out" );
g << suma;
//cout << suma;
g.close();
}
int main()
{
ifstream f( "sate.in" );
long int m, i, j, k, x, y, lung;
f >> n >> m;
f >> j >> k;
for (i = 0; i < m; i++)
{
f >> x >> y >> lung;
l[ y ].push_back( lung );
l[ x ].push_back( lung );
mat[ x ].push_back( y );
mat[ y ].push_back( x );
}
f.close();
bf( j, k );
return 0;
}