#!usr/bin/env python3



from collections import defaultdict





def main():

    #Read stdin



    fl = input().split(" ")

    V = int(fl[0])

    E = int(fl[1])

    R = int(fl[2])

    #Adjacency list

    G = defaultdict(list)

    for i in range(int(E)):

        s, t, w = [int(x) for x in input().split(" ")]

        G[s].append((t,w))

    #initialized

    d = {}

    INF = float('inf')

    #INF = 10001

    for i in range(V):

        d[i] = INF

    d[R] = 0

    q = [R]

    while q:

        u = q.pop(0)

        for v in G[u]:

            if d[v[0]] > d[u] + v[1]:

                d[v[0]] = d[u] + v[1]



                q.append(v[0])



    for k in range(V):

        if d[k] == float('inf'):

            

            print("INF")

        else:

            print((d[k]))







if __name__ == '__main__':

    main()
from collections import defaultdict

from collections import deque

#import time



def main():

    # Read stdin

    #start = time.clock()

    fl = input().split(" ")

    V = int(fl[0])

    E = int(fl[1])

    R = int(fl[2])

    # Adjacency list

    G = defaultdict(list)

    for i in range(int(E)):

        s, t, w = [int(x) for x in input().split(" ")]

        G[s].append((t, w))

    # initialized

    d = {}

    INF = float('inf')

    # INF = 10001

    for i in range(V):

        d[i] = INF

    d[R] = 0

    q = deque([R])

    while q:

        # u = heappop(q)

        u = q.popleft()

        for v in G[u]:

            if d[v[0]] > d[u] + v[1]:

                d[v[0]] = d[u] + v[1]

                # heappush(q, v[0])

                q.append(v[0])

    #end = time.clock() - start

    for k in range(V):

        if d[k] == float('inf'):

            print("INF")

        else:

            print((d[k]))

    #print('Computation time : {}'.format(end))





if __name__ == '__main__':

    main()
#!usr/bin/env python3
from collections import defaultdict


def main():
    # Read stdin
    fl = input().split(" ")
    V = int(fl[0])
    E = int(fl[1])
    R = int(fl[2])
    # Adjacency list
    G = defaultdict(list)
    for i in range(int(E)):
        s, t, w = [int(x) for x in input().split(" ")]
        G[s].append((t, w))
    # initialized
    d = {}
    INF = float("inf")
    # INF = 10001
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = [R]
    while q:
        u = q.pop(0)
        for v in G[u]:
            if d[v[0]] > d[u] + v[1]:
                d[v[0]] = d[u] + v[1]
                q.append(v[0])
    for k in range(V):
        if d[k] == float("inf"):
            print("INF")
        else:
            print((d[k]))


if __name__ == "__main__":
    main()

from collections import defaultdict
from collections import deque

# import time
def main():
    # Read stdin
    # start = time.clock()
    fl = input().split(" ")
    V = int(fl[0])
    E = int(fl[1])
    R = int(fl[2])
    # Adjacency list
    G = defaultdict(list)
    for i in range(int(E)):
        s, t, w = [int(x) for x in input().split(" ")]
        G[s].append((t, w))
    # initialized
    d = {}
    INF = float("inf")
    # INF = 10001
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = deque([R])
    while q:
        # u = heappop(q)
        u = q.popleft()
        for v in G[u]:
            if d[v[0]] > d[u] + v[1]:
                d[v[0]] = d[u] + v[1]
                # heappush(q, v[0])
                q.append(v[0])
    # end = time.clock() - start
    for k in range(V):
        if d[k] == float("inf"):
            print("INF")
        else:
            print((d[k]))
    # print('Computation time : {}'.format(end))


if __name__ == "__main__":
    main()

-#!usr/bin/env python3 +from collections import deque - +# import time +    # start = time.clock() -    q = [R] +    q = deque([R]) -        u = q.pop(0) +        # u = heappop(q) +        u = q.popleft() +                # heappush(q, v[0]) +    # end = time.clock() - start +    # print('Computation time : {}'.format(end))