from sys import stdin

from collections import defaultdict, deque

import math



readline = stdin.readline





v, e, r = list(map(int, readline().split()))



g = defaultdict(list)

for i in range(e):

    s, t, length = list(map(int, readline().split()))

    g[s].append((length, t))

d = [float('inf')] * v

d[r] = 0

que = deque([(d[r], r)])

while que:

    du, u = que.popleft()

    for length, v in g[u]:

        if d[v] > du + length:

            d[v] = du + length

            que.append((d[v], v))

for di in d:

    print(('INF' if math.isinf(di) else di))
from sys import stdin

from collections import defaultdict

from heapq import heappush, heappop

import math



readline = stdin.readline



v, e, r = list(map(int, readline().split()))



g = defaultdict(list)

for i in range(e):

    s, t, length = list(map(int, readline().split()))

    g[s].append((length, t))

d = [float('inf')] * v

d[r] = 0

heap = [(d[r], r)]

while heap:

    du, u = heappop(heap)

    for length, v in g[u]:

        if d[v] > du + length:

            d[v] = du + length

            heappush(heap,(d[v], v))

for di in d:

    print(('INF' if math.isinf(di) else di))
from sys import stdin
from collections import defaultdict, deque
import math

readline = stdin.readline
v, e, r = list(map(int, readline().split()))
g = defaultdict(list)
for i in range(e):
    s, t, length = list(map(int, readline().split()))
    g[s].append((length, t))
d = [float("inf")] * v
d[r] = 0
que = deque([(d[r], r)])
while que:
    du, u = que.popleft()
    for length, v in g[u]:
        if d[v] > du + length:
            d[v] = du + length
            que.append((d[v], v))
for di in d:
    print(("INF" if math.isinf(di) else di))

from sys import stdin
from collections import defaultdict
from heapq import heappush, heappop
import math

readline = stdin.readline
v, e, r = list(map(int, readline().split()))
g = defaultdict(list)
for i in range(e):
    s, t, length = list(map(int, readline().split()))
    g[s].append((length, t))
d = [float("inf")] * v
d[r] = 0
heap = [(d[r], r)]
while heap:
    du, u = heappop(heap)
    for length, v in g[u]:
        if d[v] > du + length:
            d[v] = du + length
            heappush(heap, (d[v], v))
for di in d:
    print(("INF" if math.isinf(di) else di))

-from collections import defaultdict, deque +from collections import defaultdict +from heapq import heappush, heappop -que = deque([(d[r], r)]) -while que: -    du, u = que.popleft() +heap = [(d[r], r)] +while heap: +    du, u = heappop(heap) -            que.append((d[v], v)) +            heappush(heap, (d[v], v))