#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>

#define P pair<int,int>

using namespace std;

int main(){

  int v,e,r;
  cin >> v >> e >>r;
  vector<vector<P>> G(v);
  for(int i=0;i<e;i++){
    long long int s,t,d;
    cin >> s >> t >> d;
    G[s].push_back({d,t});
  }

  vector<bool> seen(v,false);
  vector<long long> dist(v,10000000000);

  dist[r]=0;
  seen[r]=1;

  priority_queue<P,vector<P>,greater<P>> que;
  que.push(P(0,r));

  while(!que.empty()){
    P p = que.top();
    que.pop();
    int u = p.second;
    if(dist[u] < p.first){
      continue;
    }
    for(int i=0;i<G[u].size();i++){
      P e = G[u][i];
      if(dist[e.second] > dist[u] + e.first){
        dist[e.second] = dist[u] + e.first;
        que.push(P(dist[e.second],e.second));
      }
    }
  }
  
  for(int i=0;i<v;i++){
    if(dist[i]!=10000000000)cout << dist[i] <<endl;
    else cout << "INF" << endl;
  }
  




}
