#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
using namespace std;
int a[1200][1200],jl1,jl2,n,m,v,i,j,k;
long long tma=0;
int main(){
freopen("sparty.in","r",stdin);
freopen("sparty.out","w",stdout);
cin>>n>>m>>v;
for (i=1;i<=n;++i)
for (j=1;j<=n;++j)
a[i][j]=10000000;
for (i=1;i<=m;++i)
{
int x,y,z;
cin>>x>>y>>z;
a[x][y]=z;
}
for (k=1;k<=n;++k)
for (i=1;i<=n;++i)
if (i!=k)
for (j=1;j<=n;++j)
if (i!=j)
{
if (a[k][j]+a[i][k]<a[i][j])
a[i][j]=a[i][k]+a[k][j];
}
for (int i=1;i<=n;++i)
if (i!=v)
if (a[i][v]+a[v][i]>tma)
tma=a[i][v]+a[v][i];
cout<<tma;
}