标准版能过,555~
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m, t;
vector<pii> mp[100005];
int f[100005] = { 0 };
bool val[100005] = { 0 };
void dij(int xx) {
f[xx] = 0;
priority_queue<pii> q;
q.push({ 0, xx });
int ans = 0;
while (q.size()) {
pii tt = q.top();
q.pop();
if (val[tt.y]) continue;
++ans;
val[tt.y] = 1;
for (int i = 0; i < mp[tt.y].size(); ++i) {
if (!val[mp[tt.y][i].x] && f[tt.y] + mp[tt.y][i].y < f[mp[tt.y][i].x]) {
f[mp[tt.y][i].x] = f[tt.y] + mp[tt.y][i].y;
q.push({ -f[mp[tt.y][i].x], mp[tt.y][i].x });
}
}
if (ans == n - 1) break;
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
memset(f, INF, sizeof f);
cin >> n >> m >> t;
int l, r, w;
while (m--) {
cin >> l >> r >> w;
mp[l].push_back({ r, w });
}
dij(t);
for (int i = 1; i <= n; ++i)
if(f[i] == INF)
cout << "2147483647 ";
else
cout << f[i] << " ";
return 0;
}