#include<bits/stdc++.h>
using namespace std;
int a[1200][1200],jl1,jl2,n,m,v;
long long tma=0;
int main(){
freopen("sparty.in","r",stdin);
freopen("sparty.out","w",stdout);
cin>>n>>m>>v;
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
a[i][j]=10000000;
for (int i=1;i<=m;++i)
{
int x,y,z;
cin>>x>>y>>z;
a[x][y]=z;
}
for (int k=1;k<=n;++k)
for (int i=1;i<=n;++i)
if (i!=k)
for (int 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;
}