#include<iostream>
#include
<queue>
#define MAXN 1001
using namespace std;

struct type1
{
    
int v, w;
    
bool operator < (const type1& e) const {
        
return w > e.w;
    }
};

int MAP[MAXN][MAXN], D[MAXN], D2[MAXN];

void dijk(int s, int n)
{
    priority_queue
<type1> q;
    
bool mk[MAXN] = {false};
    type1 e 
= {s, 0}, ne;
    
int i, tmp;

    D[s] 
= 0;
    q.push(e);
    
while (!q.empty())
    {
        e 
= q.top();
        q.pop();
        
if (mk[e.v])
            
continue;
        
for (mk[e.v] = true, i = 0; i < n; i++)
        {
            
if (!mk[i] && MAP[e.v][i] < INT_MAX && (tmp = e.w + MAP[e.v][i]) < D[i])
            {
                D[ne.v 
= i] = ne.w = tmp;
                q.push(ne);
            }
        }
    }
}

int main()
{
    
int n, m, x;
    
int i, j, a, b, t, max = 0;

    scanf(
"%d %d %d"&n, &m, &x);
    
for (i = 0; i < n; i++)
        
for (D[i] = INT_MAX, j = 0; j < n; j++)
            MAP[i][j] 
= INT_MAX;
    
while (m--)
    {
        scanf(
"%d %d %d"&a, &b, &t);
        MAP[a
-1][b-1= t;
    }
    dijk(x
-1, n);
    
for (i = 0; i < n; i++)
    {
        D2[i] 
= D[i];
        D[i] 
= INT_MAX;
    }
    
for (i = 0; i < n; i++)
        
for (j = i + 1; j < n; j++)
        {
            t 
= MAP[i][j];
            MAP[i][j] 
= MAP[j][i];
            MAP[j][i] 
= t;
        }
    dijk(x
-1, n);
    
for (i = 0; i < n; i++)
        
if ((t = D[i] + D2[i]) > max)
            max 
= t;
    printf(
"%d\n", max);
    
return 0;
}