function Main(input) {
    function Heap () {
        this.heap = new Array();
        this.size = 0;
    }
    Heap.prototype.push = function (val) {
        var k = this.size++;
    
        while( 0 < k ) {
            var p = Math.floor( (k - 1) / 2 );
            
            if( this.heap[p] <= val ) break; //★
            
            this.heap[k] = this.heap[p];
            k = p;
        }
        this.heap[k] = val;
    }
    Heap.prototype.pop = function () {
        var ret = this.heap[0];
        var x = this.heap[--this.size];
        
        var k = 0;
        while( k * 2 + 1 < this.size ) {
            var a = k * 2 + 1;
            var b = k * 2 + 2;
            if( b < this.size && this.heap[b] < this.heap[a] ) a = b;
            
            if( x <= this.heap[a] ) break; //★
    
            this.heap[k] = this.heap[a];
            k = a;
        }
        this.heap[k] = x;
        return ret;
    }
    Heap.prototype.top = function () {
        return this.heap[0];
    }
    Heap.prototype.size = function () {
        return this.size;
    }
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var lVl = parseInt(input[0][0]);
    var lEl = parseInt(input[0][1]);
    var r = parseInt(input[0][2]);
    var graph = Array.from({length: lVl}, () => []);
    var line;
    for (var i = 0; i < lEl; i++){
        line = input[i + 1].map(e => parseInt(e, 10));
        graph[line[0]].push([line[1], line [2]]);
        // graph[line[1]].push([line[0], line [2]]);
    }
    
    var q = new Heap();
    var tmpDList1 = [];
    tmpDList1[0] = [r];
    ansList = Array.from({length: lVl}, () => Number.MAX_SAFE_INTEGER);
    // var tmpDList2 = Array.from({length: lVl}, () => Number.MAX_SAFE_INTEGER);
    // tmpDList2[r] = 0;
    q.push(0);
    var fixedD, fixedNode;
    while (true){
        // console.log(q);
        fixedD = q.pop();
        fixedNode = tmpDList1[fixedD].pop();
        if (ansList[fixedNode] > fixedD) {
            ansList[fixedNode] = fixedD;
            for (var x of graph[fixedNode]){
                if (tmpDList1[x[1] + fixedD] == null ) tmpDList1[x[1] + fixedD] = [x[0]];
                else tmpDList1[x[1] + fixedD].push(x[0]);
                q.push(x[1] + fixedD);
            }
        }
        if (q.size === 0) break;
        // console.log(ansList);
        // console.log(tmpDList1);
    }
    var ans = ansList.map(e => {
        if (e === Number.MAX_SAFE_INTEGER) return "INF";
        else return e.toString(10);
    })

    console.log(ans.join("\n"));

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
