#include<stdio.h>
int R=1,C=1,H[1000010]={0};
int N[1000010]={-1000};
//ヒープに入れる
void hin(int a){
  int i=C++;
  for(N[R]=a;a<N[H[i/2]];i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//ヒープから最小値を取り出す
int hout(){
  int rt=H[1],nt=1,i=0,k=H[--C];
  while(nt-i){
    H[i=nt]=k;
    if(i*2  <C&&N[  k  ]>N[H[i*2  ]])H[i]=H[nt=i*2  ];
    if(i*2+1<C&&N[H[nt]]>N[H[i*2+1]])H[i]=H[nt=i*2+1];
  }
  return rt;
}
int CO[500010];
int i,id[500010],ta[100010],nt[500010],f[500010]={0};
void dijk(int v,int e,int *fr,int *to,int *co,int mi){
  //int i,id[500010],ta[100010],nt[500010],f[500010]={0};
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<v;i++)CO[i]=1000000000;
  for(i=CO[mi]=0;i<e;i++){
    nt[i]=ta[fr[i]];
    ta[fr[i]]=i;
  }
  while(f[mi]-1){
    f[mi]=1;
    for(i=ta[mi];i+1;i=nt[i]){
      if(CO[to[i]]>CO[mi]+co[i])hin(CO[id[R]=to[i]]=CO[mi]+co[i]);
    }
    while(f[mi]&&C-1)mi=id[hout()];
  }
}
int main(){
  int n,m,s,a[500010],b[500010],c[500010],i;
  scanf("%d %d %d",&n,&m,&s);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  dijk(n,m,a,b,c,s);
  for(i=0;i<n;i++)CO[i]-1000000000?printf("%d\n",CO[i]):printf("INF\n");
  return 0;
}