#include<stdio.h>
#include<stdlib.h>
struct node{
  int key;
  int cost;
  struct node *next;
};
typedef struct node *GG;
 
GG G[100001];
GG MNode(int,int,GG);
void Insert(int,int,int);
int main()
{
  int i,j,n,count=0,v,c,c1,v1,e,r;
  int color[100001],d[100001],pi[100001],mincost,ii;
  GG GGG;
  scanf("%d%d%d",&v,&e,&r);
  for(i=0;i<v;i++)G[i]=MNode(0,0,NULL);
  for(i=0;i<e;i++){
    scanf("%d%d%d",&n,&v1,&c1);
    Insert(n,v1,c1);
  }
  for(i=0;i<v;i++){
    color[i]=0;
    pi[i]=-1;
    d[i]=10000001;
  }
  d[r]=0;
  
  while(1){
    mincost=10000001;
    ii=-1;
    for(i=0;i<v;i++){
      if(color[i]!=2 && d[i]<mincost){
        mincost=d[i];
        ii=i;
      }
    } 
    if(mincost==10000001)break;
    color[ii]=2;
    for(GGG=G[ii]->next;GGG!=NULL;GGG=GGG->next){
      if(color[GGG->key]!=2 && (GGG->cost+d[ii])<d[GGG->key]){
	pi[GGG->key]=ii;
	d[GGG->key]=GGG->cost+d[ii];
	color[GGG->key]=1;
      }
    }
      
  }
  for(i=0;i<v;i++){
    if(d[i]!=10000001)printf("%d\n",d[i]);
    else printf("INF\n");
  }
  
  return 0;
}
 
GG MNode(int key,int cost,GG Node)
{
  GG n;
  n=(GG)malloc(sizeof(struct node));
  n->key=key;
  n->cost=cost;
  n->next=Node;
  return n;
}
void Insert(int s,int t,int u)
{
  GG GGG;
  GGG=MNode(t,u,G[s]->next);
  G[s]->next=GGG;
}