import heapq

import math





def main():

    nvertices, nedges, s = list(map(int, input().split()))

    edges = [[] for i in range(nvertices)]

    for i in range(nedges):

        u, v, w = list(map(int, input().split()))

        edges[u].append((v, w))

    INF = float('inf')

    hq = []

    for i in range(nvertices):

        heapq.heappush(hq, ((0 if i == s else INF), i))

    heapq.heapify(hq)

    weights = [INF] * nvertices

    weights[s] = 0

    while hq:

        d, u = heapq.heappop(hq)

        if d > weights[u]:

            continue

        for v, w in edges[u]:

            if weights[u] + w < weights[v]:

                weights[v] = weights[u] + w

                heapq.heappush(hq, (weights[v], v))



    for w in weights:

        print(("INF" if math.isinf(w) else w))





main()
import heapq

import math





def main():

    nvertices, nedges, s = list(map(int, input().split()))

    edges = [[] for i in range(nvertices)]

    for i in range(nedges):

        u, v, w = list(map(int, input().split()))

        edges[u].append((v, w))

    INF = float('inf')

    hq = [(0, s)]

    weights = [INF] * nvertices

    weights[s] = 0

    while hq:

        d, u = heapq.heappop(hq)

        if d > weights[u]:

            continue

        for v, w in edges[u]:

            if weights[u] + w < weights[v]:

                weights[v] = weights[u] + w

                heapq.heappush(hq, (weights[v], v))



    for w in weights:

        print(("INF" if math.isinf(w) else w))





main()
import heapq
import math


def main():
    nvertices, nedges, s = list(map(int, input().split()))
    edges = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v, w = list(map(int, input().split()))
        edges[u].append((v, w))
    INF = float("inf")
    hq = []
    for i in range(nvertices):
        heapq.heappush(hq, ((0 if i == s else INF), i))
    heapq.heapify(hq)
    weights = [INF] * nvertices
    weights[s] = 0
    while hq:
        d, u = heapq.heappop(hq)
        if d > weights[u]:
            continue
        for v, w in edges[u]:
            if weights[u] + w < weights[v]:
                weights[v] = weights[u] + w
                heapq.heappush(hq, (weights[v], v))
    for w in weights:
        print(("INF" if math.isinf(w) else w))


main()

import heapq
import math


def main():
    nvertices, nedges, s = list(map(int, input().split()))
    edges = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v, w = list(map(int, input().split()))
        edges[u].append((v, w))
    INF = float("inf")
    hq = [(0, s)]
    weights = [INF] * nvertices
    weights[s] = 0
    while hq:
        d, u = heapq.heappop(hq)
        if d > weights[u]:
            continue
        for v, w in edges[u]:
            if weights[u] + w < weights[v]:
                weights[v] = weights[u] + w
                heapq.heappush(hq, (weights[v], v))
    for w in weights:
        print(("INF" if math.isinf(w) else w))


main()

-    hq = [] -    for i in range(nvertices): -        heapq.heappush(hq, ((0 if i == s else INF), i)) -    heapq.heapify(hq) +    hq = [(0, s)]