object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val INF = Int.MaxValue / 10
    val Vs, Es, root = sc.nextInt()
    val E = (0 until Es) map { _ =>
      val s, t, d = sc.nextInt()
      (s, t, d)
    }
    val W = Array.fill(Vs)(INF)
    W(root) = 0
    // ベルマンフォード, |V|-1回, 全ての辺を緩和させる
    (0 until Vs - 1) foreach { _ =>
      E foreach { case (u, v, w) =>
        if (W(v) > W(u) + w) {
          W(v) = W(u) + w
        }
      }
    }

    println(W. map { w =>
      if (w == INF) "INF" else w.toString
    }. mkString("\n"))
  }

}

