spfa模板
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#define LL long long
using namespace std;
const int N=1e6+100;
const LL M=pow (2,31)-1,MM=0x3f;
struct sb
{
int uu,ww,to,next;
}a[N];
int u,v,w,n,m,s,t,tot,f[N],dis[N],last[N];
queue <int> q;
void add (int u,int v,int w)
{
a[++tot].ww=w;
a[tot].to=v;
a[tot].next=last[u];
last[u]=tot;
}
void spfa ()
{
memset (dis,0x3f,sizeof (dis));
dis[s]=0;
q.push (s);
while (!q.empty ())
{
int h=q.front ();
q.pop ();
for (int i=last[h];i;i=a[i].next)
{
int fg=a[i].to;
if (dis[fg]>dis[h]+a[i].ww)
{
dis[fg]=dis[h]+a[i].ww;
q.push (fg);
}
}
}
}
int main ()
{
scanf ("%d %d %d",&m,&n,&s);
for (int i=1;i<=n;i++) scanf ("%d %d %d",&u,&v,&w),add (u,v,w);
spfa ();
for (int i=1;i<=m;i++)
{
if (dis[i]>N) printf ("%d ",M);
else printf ("%d ",dis[i]);
}
return 0;
}