structnode { int v; int w; }; vector<node> e[maxn]; int dis[maxn]; bool vis[maxn]; int pre[maxn];
voiddijkstra(int s){ priority_queue<pii, vector<pii>, greater<pii>> q; memset(dis, inf, sizeof(dis)); dis[s] = 0; q.push({dis[s], s}); while(!q.empty()) { pii t = q.top(); q.pop(); int u = t.second; if(vis[u]) continue; vis[u] = true; for(node x:e[u]) { int v = x.v; int w = x.w; if(dis[v]>dis[u]+w) { dis[v] = dis[u] + w; pre[v] = u; q.push({dis[v], v}); } } } }
intmain(){ int n, m, s; cin >> n >> m >> s; for (int i = 0;i<n;i++) { pre[i] = -1; } for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; e[u].push_back((node){v, w}); // e[v].push_back((node){u, w}); } dijkstra(s); for (int i = 1; i <= n;i++) { cout << dis[i] << " "; } cout << endl; }