#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
const int inf = 0x3f3f3f;
struct nod
{
int end;
int length;
};
struct nod1
{
int to;
int len;
};
bool operator<(nod a, nod b)
{
return a.length < b.length;
}
priority_queue<nod>q;
vector<nod1>dp[N];
long long dis[N];
int vis[N];
int n, m, w;
void dijkstra()
{
memset(dis, inf, sizeof(dis));
memset(vis, 0, sizeof(vis));
dis[w] = 0;
nod y;
y.end = w;
y.length = 0;
q.push(y);
while (!q.empty())
{
int top = q.top().end;
q.pop();
if(vis[top])
{
continue;
}
for(int i=0;i<dp[top].size();i++)
{
int end_ = dp[top][i].to;
int length_ = dp[top][i].len;
dis[end_] = min(dis[end_], dis[top] + length_);
nod temp;
temp.end = end_;
temp.length = length_;
q.push(temp);
}
vis[top] = 1;
}
}
int main()
{
cin >> n >> m >> w;
for (int i = 1; i <= m; i++)
{
int s, e, d;
cin >> s >> e >> d;
nod1 t;
t.to = e;
t.len = d;
dp[s].push_back(t);
}
dijkstra();
for (int i = 1; i <= n; i++)
{
cout << dis[i] << " ";
}
}