#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
struct noe
{
int next,to,g;
}a[1000001];
int cnt=1;
int head[1000001];
int n,m,s;
typedef pair<int,int> P;
int d[1000001];
void ad(int u,int v,int w)
{
a[cnt].to=v;
a[cnt].g=w;
a[cnt].next=head[u];
head[u]=cnt++;
}
int main()
{
memset(head,-1,sizeof(head));
priority_queue<P,vector<P>,greater<P> > q;
memset(d,0x3f,sizeof(d));
cin>>n>>m>>s;
d[s]=0;
q.push(P(0,s));
for(int i=1;i<=m;i++)
{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
ad(x,y,z);
}
while(!q.empty())
{
P p=q.top();
q.pop();
int u=p.second;
if(d[u]>p.first)
{
continue;
}
else
{
for(int i=head[u];i!=-1;i=a[i].next)
{
int v=a[i].to;
if(d[v]>d[u]+a[i].g)
{
d[v]=d[u]+a[i].g;
q.push(P(d[v],v));
}
}
}
}
for(int i=1;i<=n;i++)
{
printf("%d ",d[i]);
}
return 0;
}
3个TLE,求调