#include <bits/stdc++.h> #define N 200001 #define M 500001 #define pr pair<int,int> #define mk make_pair using namespace std; const int INF = 0x7fffffff; struct Node{ int v,val,nxt; }e[M]; int n,m,s,top; int dist[N],head[N]; void add(int u,int v,int w){ ++top; e[top].v = v; e[top].val = w; e[top].nxt = head[u]; head[u] = top; } priority_queue<pr,vector<pr>,greater<pr> > q; void Dijkstra(){ for(int i = 1; i <= n; ++i) dist[i] = INF; dist[s] = 0; q.push(mk(0, s)); while(!q.empty()){ int u = q.top().second; int d = q.top().first; q.pop(); if(dist[u] < d) continue; for(int i = head[u]; i; i = e[i].nxt){ if(dist[e[i].v] > d + e[i].val){ dist[e[i].v] = d + e[i].val; q.push(mk(dist[e[i].v], e[i].v)); } } } for(int i = 1; i <= n; ++i) cout << dist[i] << " "; //cout << dist[n]; } int main(){ cin >> n >> m >> s; for(int i = 1, u, v, w; i <= m; ++i){ cin >> u >> v >> w; add(u, v, w); } Dijkstra(); return 0; }