#include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

#define Edge pair< i_i, int>
#define Graph vector< vp >

//???????§????????????????(???????????????)
//Dijkstra O((E+V)logV)
//dist: ?§????????????????????????§??????????????¢
//?????????: ??????????????¨????????????(??????-1)
vector<int> dijkstra(Graph &g, int s, vi &dist)
{
    int n = g.size();
    vi visited(n, 0); visited[s] = 1;
    vi prev(n, -1);
    dist.assign(n, INF); dist[s] = 0;
    priority_queue< Edge, vector< Edge >, greater< Edge > > pq;
    pq.push(Edge(i_i((int)0, s), (int)-1)); // ????????? ??? ???
    while (pq.size()) {
        int d = pq.top().ffir, v = pq.top().fsec, u = pq.top().second;
        pq.pop();
        if (dist[v] < d) continue; //?????§???????????§???????????°??????
        visited[v] = 2; prev[v] = u;
        for (i_i &e : g[v]) {
            if (visited[e.fir] == 2) continue;
            if (dist[e.fir] > dist[v] + e.sec) {
                dist[e.fir] = dist[v] + e.sec;
                pq.push(Edge(i_i(dist[e.fir], e.fir), v));
                visited[e.fir] = 1;
            }
        }
    }
    return prev;
}

 
signed main()
{
    int2(n, m);
    Int(st);
    Graph g(n, vp());
    vi ans(n);

    rep(i, m) {
        int2(s, t);
        Int(d);
        g[s].pb(i_i(t, d));
    }
    dijkstra(g, st, ans);
    rep(i, n) {
        if (ans[i] == INF) {
            cout << "INF" << endl;
        } else {
            cout << ans[i] << endl;
        }
    }


    return 0;
}
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
int n, m, r; const int W(1), B(0);
vector<vector<pair<int, int>>>adj; // dist, cost
void dijkstra() {
	vector<int>d(n, INF), color(n, W);
	d[r] = 0;
	priority_queue<pair<int, int>>pq; // d[v], v
	pq.push(make_pair(0, r));
	while (!pq.empty()) {
		pair<int, int>f(pq.top()); pq.pop();
		color[f.second] = B;
		if (d[f.second] < (-1)*f.first)continue;
		rep(i, 0, adj[f.second].size()) {
			pair<int, int>u(adj[f.second][i]);
			if (color[u.first] != B&&d[f.second] + u.second < d[u.first]) {
				d[u.first] = d[f.second] + u.second;
				pq.push(make_pair((-1)*d[u.first], u.first));
			}
		}
	}
	rep(i, 0, n) {
		if (d[i] == INF)cout << "INF" << endl;
		else cout << d[i] << endl;
	}
}
signed main() {
	cin >> n >> m >> r; adj = vector<vector<pair<int, int>>>(n, vector<pair<int,int>>());
	rep(i, 0, m) {
		int s, t, d; cin >> s >> t >> d;
		adj[s].push_back(make_pair(t, d));
	}
	dijkstra();
	return 0;
}