#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <limits.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 100010;
const int MAXM = 200020;
struct Edge {
int u, v, w;
Edge(const int & _u = int(), const int & _v = int(), const int & _w = INF) : u(_u), v(_v), w(_w) {}
} edge[MAXM];
int dist[MAXN];
void BellmanFord(const int & n, const int & m, const int & s) {
dist[s] = 0;
for (int i = 0; i < n; ++i) {
int check = 0;
for (int j = 1; j <= m; ++j) {
if (dist[edge[j].v] > dist[edge[j].u] + edge[j].w) {
dist[edge[j].v] = dist[edge[j].u] + edge[j].w;
check = 1;
}
}
if (!check) {
break;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, s;
cin >> n >> m >> s;
memset(dist, INF, sizeof(dist));
for (register int i = 1; i <= m; ++i) {
register int u, v, w;
cin >> u >> v >> w;
edge[i] = Edge(u, v, w);
}
BellmanFord(n, m, s);
for (int i = 1; i <= n; ++i) {
if (dist[i] >= INF) {
cout << INT_MAX << ' ';
}
else {
cout << dist[i] << ' ';
}
}
return 0;
}