#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e6;
typedef long long LL;
LL dist[N];
int h[N],e[N],ne[N],idx=1,w[N];
bool vis[N];
int n,m,s;
struct node
{
LL v,l;
friend bool operator<(node a,node b)
{
return a.l>b.l;
}
}tmp;
int d=(1<<31)-1;
void add(int a,int b,int c)
{
e[idx]=b;
w[idx]=c;
ne[idx]=h[a];
h[a]=idx++;
}
void Dijkstra()
{
dist[s]=0;
tmp.v=s;
tmp.l=0;
priority_queue<node> q;
q.push(tmp);
while(!q.empty())
{
int u=q.top().v;
q.pop();
if(vis[u]) continue;
vis[u]=true;
for(int i=h[u];i!=-1;i=ne[i])
{
int j=e[i];
if(dist[j]>dist[u]+w[i]&&!vis[j])
{
dist[j]=dist[u]+w[i];
struct node New;
New.v=j;
New.l=dist[j];
q.push(New);
}
}
}
}
int main()
{
cin>>n>>m>>s;
memset(h,-1,sizeof h);
memset(dist,0x3f,sizeof dist);
for(int i=1;i<=m;i++)
{
int a,b,c;
cin>>a>>b>>c;
add(a,b,c);
}
Dijkstra();
for(int i=1;i<=n;i++)
{
if(dist[i]>INF/2) cout<<d<<" ";
else cout<<dist[i]<<" ";
}
return 0;
}