#include "bits/stdc++.h"
using namespace std;
typedef long long lint;

#define MAX_N 100010
//d,edge,g,P,q
lint d[MAX_N];
struct edge{
	int to;
	lint cost;
};
vector<edge> g[MAX_N];
typedef pair<lint,int> P;
priority_queue<P,vector<P>,greater<P> > q;

void pfs(int s){
	d[s]=0;q.push({0,s});
	lint cd;int v;
	while(q.size()){
		cd=q.top().first;v=q.top().second;q.pop();
		if(d[v]<cd)continue;
		for(edge &e:g[v])if(cd+e.cost<d[e.to]){
			d[e.to]=cd+e.cost;
			q.push({d[e.to],e.to});
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	lint v,e,r;cin>>v>>e>>r;
	for(int i=0;i<v;++i)d[i]=INT_MAX;
	int a,b;lint c;
	for(int i=0;i<e;++i){
		cin>>a>>b>>c;
		g[a].push_back({b,c});
	}pfs(r);
	for(int i=0;i<v;++i){
		if(d[i]==INT_MAX)cout<<"INF\n";
		else cout<<d[i]<<endl;
	}
}

