#include<bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
typedef pair<int, int> p;
struct node {
int id, w;
friend bool operator < (node a, node b){
return a.w > b.w;
}
};
int n, m, s;
vector<p> v[N];
int dis[N], vis[N];
void dijkstra(int s){
dis[s] = 0;
priority_queue<node> q;
q.push(node{s, 0});
while( !q.empty() ){
node tmp = q.top(); q.pop();
if(vis[tmp.id]) continue;
vis[tmp.id] = true;
for(int i = 0; i < v[tmp.id].size(); i ++){
int j = v[tmp.id][i].first;
int k = v[tmp.id][i].second;
if(tmp.w + k < dis[j] && !vis[j]){
dis[j] = tmp.w + k;
q.push(node{j, dis[j]});
}
}
}
}
int main() {
cin >> n >> m >> s;
for(int i = 1; i <= m; i ++){
int x, y, z;
cin >> x >> y >> z;
v[x].push_back(make_pair(y, z));
}
memset(dis, 0x3f, sizeof dis);
memset(vis, 0, sizeof vis);
dijkstra(s);
int a = INT_MAX;
for(int i = 1; i <= n; i ++){
if(dis[i] == 0x3f) cout << a << " ";
else cout << dis[i] << " ";
}
return 0;
}