const MAX_V = 100000;
const INF = Number.POSITIVE_INFINITY/4;
var V, E, r;
var G;
var d;

var PriorityQueue = require('priorityqueuejs');

function dijkstra( s )
{
  var pque = new PriorityQueue(function(a,b) { 
    if( a.dist != b.dist )
      return a.dist-b.dist;

    return a.v-b.v;
  });
  d[s] = 0;
  pque.enq( { dist: 0, v: s } );

  while( !pque.isEmpty() )
  {
    var p = pque.deq();
    
    if( d[p.v] < p.dist )
      continue;

    for( var e of G[p.v] )
    {
      if( d[e.to] > d[p.v] + e.cost )
      {
        d[e.to] = d[p.v] + e.cost;
        pque.enq( { dist: d[e.to], v: e.to } );
      }
    }
  }
}

(function main( input )
{
  var lines = input.trim().split('\n');
  var fst = true;

  for( var l of lines )
  {
    var words = l.split(' ').map(Number);

    if( fst )
    {
      V = words[0];
      E = words[1];
      r = words[2];

      G = [];
      for( var i = 0; i < V; ++i )
        G[i] = [];

      d = (new Array(V)).fill(INF);
    }
    else
      G[words[0]].push( { to: words[1], cost: words[2] } );

    fst = false;
  }

  dijkstra( r );

  d.forEach( function(v) { console.log( v == INF ? "INF" : v ) } );
})( require('fs').readFileSync( '/dev/stdin', 'utf8' ) );