#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 1, inf = 1e16 + 7;
struct node
{
int x, y;
bool operator < (const node &z) const
{
return y > z.y;
}
};
priority_queue<node>q;
vector<node>v[N];
int n, m, s, vis[N], ans[N];
signed main()
{
cin >> n >> m >> s;
for(int i = 0; i <= 100000; i++)
{
ans[i] = inf;
}
ans[s] = 0;
while(m--)
{
int x, y, z;
cin >> x >> y >> z;
v[x].push_back({y, z});
v[y].push_back({x, z});
}
q.push({s, 0});
while(!q.empty())
{
int now = q.top().x;
q.pop();
if(vis[now])
{
continue;
}
vis[now] = 1;
for(int i = 0; i < v[now].size(); i++)
{
if(ans[v[now][i].x] > ans[now] + v[now][i].y)
{
ans[v[now][i].x] = ans[now] + v[now][i].y;
if(!vis[v[now][i].x])
{
q.push({v[now][i].x, ans[v[now][i].x]});
}
}
}
}
for(int i = 1; i <= n; i++)
{
if(ans[i] >= inf)
{
cout << -1 << " ";
}
else
{
cout << ans[i] << " ";
}
}
}
为了复习重新打了一遍,为什么52?求大佬挑错