void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m, s; rd(n, m, s);
  alias edge=Edge!(int);
  auto g=new edge[][](n);
  foreach(_; 0..m){
    int a, b, c; rd(a, b, c);
    g[a]~=edge(b, c);
  }

  auto dist=dijkstra!(int)(g, s);
  foreach(d; dist){
    if(d==(int).max) writeln("INF");
    else writeln(d);
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


struct Edge(T){
  int to;
  T cost;
}

T[] dijkstra(T, alias edge=Edge!(T))(edge[][] g, int s){
  import std.algorithm, std.typecons, std.typetuple, std.container;
  const inf=T.max;
  auto dist=new T[](g.length);
  fill(dist, inf);
  dist[s]=T.init;
  alias P=edge;
  auto q=new BinaryHeap!(Array!P, "a.cost>b.cost");
  q.insert(P(s, dist[s]));
  while(q.length>0){
    auto cost=q.front.cost;
    auto u=q.front.to;
    q.removeFront;
    foreach(e; g[u]){
      if(cost+e.cost<dist[e.to]){
        dist[e.to]=cost+e.cost;
        q.insert(P(e.to, dist[e.to]));
      }
    }
  }
  return dist;
}

