/*
* @Description: To iterate is human, to recurse divine.
* @Autor: Recursion
* @Date: 2022-04-08 15:18:26
* @LastEditTime: 2022-04-08 16:02:37
*/
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 5e5 + 1;
struct edge{
int u;
int v;
int w;
int next;
}e[N];
int head[N],cnt,n,m,s,vis[N],dis[N];
priority_queue<pair<int,int> >q;//大根堆(优先队列),第一维为d的相反数(变成小根堆),第二维为节点编号
void add(int u ,int v,int w)
{
e[++cnt].u = u;
e[cnt].v = v;
e[cnt].w = w;
e[cnt].next = head[u];
head[u] = cnt;
}
void dijkstra()
{
for(int i = 1;i <= n;i ++)
dis[i] = INF;
dis[s] = 0;
q.push(make_pair(0,s));
while(!q.empty()){
int x = q.top().second;
q.pop();
if(vis[x])
continue;
vis[x] = 1;
for(int i = head[x];i ;i = e[i].next){
int v = e[i].v;
if(dis[v] > dis[x] + e[i].w){
dis[v] = dis[x] + e[i].w;
q.push(make_pair(-dis[v],v));
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int x,y,z;
cin >> n >> m >> s;
for(int i = 1;i <= m;i ++){
cin >> x >> y >> z;
add(x,y,z);
}
dijkstra();
for(int i = 1;i <= n;i ++)
cout << dis[i]<< " ";
return 0;
}
10-08
703
07-30
208