显示代码纯文本
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,x,p,q,z,minx;
int f[1001][1001];
int main()
{
freopen("sparty.in","r",stdin);
freopen("sparty.out","w",stdout);
memset(f,127/3,sizeof(f));
scanf("%d%d%d",&n,&m,&x);
for (int i=1; i<=m; ++i)
{
scanf("%d%d%d",&p,&q,&z);
f[p][q]=z;
f[p][p]=0;
f[q][q]=0;
}
for (int k=1; k<=n; ++k)
for (int i=1; i<=n; ++i)
for (int j=1; j<=n; ++j)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
for (int i=1; i<=n; ++i) minx=max(minx,f[i][x]+f[x][i]);
printf("%d\n",minx);
}