text: import heapq
  import math
  
  V, E = map(int, input().split())
  K = int(input())
  
  graph = [[] for _ in range(V + 1)]
  
  for _ in range(E):
      u, v, w = map(int, input().split())
      graph[u].append((v, w))
  
  distance = [math.inf] * (V + 1)
  
  
  def dijkstra(start):
      queue = []
      heapq.heappush(queue, (0, start))
      distance[start] = 0
      while queue:
          dist, now = heapq.heappop(queue)
          if distance[now] < dist:
              continue
          for adj in graph[now]:
              cost = dist + adj[1]
              if cost < distance[adj[0]]:
                  distance[adj[0]] = cost
                  heapq.heappush(queue, (cost, adj[0]))
  
  
  dijkstra(K)
  
  for i in range(1, len(distance)):
      if distance[i] == math.inf:
          print('INF')
      else:
          print(distance[i])
  