#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int INF = 2e9;
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m, s; cin >> n >> m >> s;
  struct edge { int to, cost; };
  vector< vector<edge> > adj(n);
  for (int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    adj[a].push_back(edge{b, c});
  }
  vector<int> d(n, INF);
  priority_queue<P, vector<P>, greater<P> > pq;
  d[s] = 0;
  pq.push(P(0, s));
  while (not pq.empty()) {
    P p = pq.top(); pq.pop();
    int v = p.second;
    for (auto&& i : adj[v]) {
      if (d[i.to] <= d[v] + i.cost) continue;
      d[i.to] = d[v] + i.cost;
      pq.push(P(d[i.to], i.to));
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (d[i] == INF ? "INF" : to_string(d[i])) << '\n';
  }
  return 0;
}
