#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define B 33

template<typename T>
class RadixHeap {
  struct Val {
    int x; T key;

    bool operator<(const Val &other) {
      return x < other.x;
    }
  };
  vector<Val> data[B];
  int last = 0, siz = 0;

  inline int bsr(int x) {
    if(x == 0) return -1;
    return 31-__builtin_clz(x);
  }

public:
  inline void push(T key, int x) {
    assert(last <= x);
    ++siz;
    data[bsr(x^last)+1].emplace_back(Val{x, key});
  }

  inline Val pop() {
    assert(siz > 0);
    if(!data[0].size()) {
      int i = 1;
      while(!data[i].size()) ++i;
      Val &em = *min_element(data[i].begin(), data[i].end());
      for(Val &e : data[i]) {
        if(e.key == em.key) {
          --siz;
          continue;
        }
        data[bsr(e.x^em.x)+1].emplace_back(e);
      }
      data[i].clear();
      return em;
    }
    --siz;
    Val &em = data[0].back();
    data[0].pop_back();
    return em;
  }

  inline bool empty() {
    return siz == 0;
  }

  inline int size() {
    return siz;
  }
};

struct Edge {
  int to; ll cost;
};

const int inf = 1e9+1;

#define N 100004
int n;
vector<Edge> g[N];
int dist[N];

void dijkstra(int s) {
  RadixHeap<int> que;
  que.push(s, 0);
  for(int i=0; i<n; ++i) dist[i] = inf;
  dist[s] = 0;

  while(!que.empty()) {
    auto p = que.pop();
    int co = p.x; int v = p.key;
    if(dist[v] < co) continue;
    for(auto &e : g[v]) {
      if(co + e.cost < dist[e.to]) {
        dist[e.to] = co + e.cost;
        que.push(e.to, dist[e.to]);
      }
    }
  }
}

int main() {
  int m, r;
  cin.tie(0); ios_base::sync_with_stdio(false);

  cin >> n >> m >> r;
  rep(i, m) {
    int s, t, d;
    cin >> s >> t >> d;
    g[s].emplace_back(Edge{t, d});
  }

  dijkstra(r);

  rep(i, n) {
    if(dist[i] == inf) {
      cout << "INF" << "\n";
    } else {
      cout << dist[i] << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 18212