#include<iostream>
using namespace std;
#define INF 10000000
#define MAX 1002
int D[MAX];
int G[MAX][MAX];
int d[MAX];
int a[MAX][MAX];
void Dijkstra(int n,int s)
{
int i,j,w,minc,mark[MAX];
for (i=1;i<=n;i++)
mark[i]=0;
for (i=1;i<=n;i++)
D[i]=G[s][i];
mark[s]=1;D[s]=0;
for (i=2;i<=n;i++)
{
minc=INF;
w=0;
for
(j=1;j<=n;j++)
if
((mark[j]==0)&&(minc>=D[j]))
{minc=D[j];w=j;}
mark[w]=1;
for
(j=1;j<=n;j++)
if
((mark[j]==0)&&(G[w][j]!=INF)&&(D[j]>D[w]+G[w][j]))
D[j]=D[w]+G[w][j];
}
return ;
}
void Dijkstra22(int n,int s)
{
int i,j,w,minc,mark[MAX];
for (i=1;i<=n;i++)
mark[i]=0;
for (i=1;i<=n;i++)
d[i]=a[s][i];
mark[s]=1;d[s]=0;
for (i=2;i<=n;i++)
{
minc=INF;
w=0;
for
(j=1;j<=n;j++)
if
((mark[j]==0)&&(minc>=d[j]))
{minc=d[j];w=j;}
mark[w]=1;
for
(j=1;j<=n;j++)
if
((mark[j]==0)&&(a[w][j]!=INF)&&(d[j]>d[w]+a[w][j]))
d[j]=d[w]+a[w][j];
}
return ;
}
int main()
{
int N, M, X;
int i, j;
int b, e, t;
while(scanf("%d%d%d", &N,
&M, &X) != EOF) {
//fill(D, D + MAX, INF);
//fill(d, d + MAX, INF);
for(i = 1; i <
MAX; i ++)
for(j = 1; j
<= i; j ++) {
if(i
== j)
G[i][j]
= a[i][j] = 0;
else
G[i][j]
= G[j][i] = a[i][j] = a[j][i] = INF;
}
while(M --) {
scanf("%d%d%d",
&b, &e, &t);
G[b][e] =
t;
a[e][b] =
t;
//矩阵转置
}
Dijkstra(N, X);
Dijkstra22(N, X);
int max = -1;
for(i = 1; i <=
N; i ++)
if(max
< d[i] + D[i])
max
= d[i] + D[i];
printf("%d\n", max);
}
return 0;
}