#include <bits/stdc++.h> using namespace std; #define int long long const int M = 2e6 + 5; int vis[M], ans[M]; struct edge { int to, w; }; vector<edge> f[M]; void add(int x, int y, int l) { f[x].push_back({y, l}); } void dij(int s, int n) { priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> p; for (int i = 1; i <= n; i++) ans[i] = 1e18; ans[s] = 0; p.push({0, s}); while (!p.empty()) { auto [dis, id] = p.top(); p.pop(); if (vis[id]) continue; vis[id] = 1; for (auto [y, w] : f[id]) { if (w + ans[id] < ans[y]) { ans[y] = w + ans[id]; p.push({ans[y], y}); } } } for (int i = 1; i <= n; i++) cout << ans[i] << " "; for (int i = 1; i <= n; ++i) { f[i].clear(); vis[i] = 0; } } void solve() { int n, m, s, x, y, l; cin >> n >> m >> s; for (int i = 1; i <= m; ++i) { cin >> x >> y >> l; add(x, y, l); } dij(s, n); } signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }

